Useful Commands UNIX SHELL Script part3

                      Part1                                                            Part2


2. Now to fetch the ERP_LOGIN details which would be used if we need to connect to SQLPLUS in our SHELL SCRIPT

Syntax:
erp_login=`echo $1 | cut -d " " -f3 | cut -d "=" -f2`
export erp_login
l_erp_login=`echo $erp_login | sed "s/\"//g"` -- This statement is used to truncate “ (double quotes)

3. Now if we need to connect to SQLPLUS below is the syntax

Syntax:
sqlplus -s $<ERP_LOGIN><<ENDOFSQL
<SQL STATEMENT>
exit;
ENDOFSQL
Example:
sqlplus -s $l_erp_login <<ENDOFSQL
set serveroutput on
SET head off
SET feed off
SET echo off
SET pause off
SET termout off
SET verify off
SELECT sysdate FROM DUAL;
exit;
ENDOFSQL
Here Exit – To exist from the SQL session
L_erp_login – This variable holds the erp_login details
The above block would return the system date

4. To send mail we use a utility “MAILX”

Syntax:
mailx -s “<Subject for a Mail>” <mail_id>

5. Sending a mail with the Body

Syntax:
echo “<Contents_Of_body>” | mailx -s “<Subject>” <mail_ID>

6. To connect to the remote server

Syntax:
sftp <Remote_User_Name>@<Remote_Host_Name> << EOF
<Statements to execute>
bye
EOF

List of commands that can be executed in a SFTP Block

get [flags] remote-path [local-path]
Retrieve the remote-path and store it on the local machine. If the local path name is not specified, it is given the same name it has on the remote machine.
put [flags] local-path [local-path]
Upload local-path and store it on the remote machine. If the remote path name is not specified, it is given the same name it has on the local machine.
rename oldpath newpath
Rename remote file from oldpath to newpath.
ln oldpath newpath
Create a symbolic link from oldpath to newpath.
rm path
Delete remote file specified by path.
lmkdir path
Create local directory specified by path.
Bye
Quit sftp.
exit
Quit sftp.
quit
Quit sftp.
cd path
Change remote directory to path.
lcd path
Change local directory to path.
ls [path]
Display remote directory listing of either path or current directory if path is not specified.


                      Part1                                                            Part2

*/

No comments:

Post a Comment