1820751 Members
3478 Online
109627 Solutions
New Discussion юеВ

About shell script

 
haeman
Frequent Advisor

About shell script

I have two question2

1. I use the command "comp" to compare the difference of two directory , then output will be write (appending) to a log,

eg. comp directory1 directory2 >> /tmp/comp_log

it is OK , but if I want when write the output to the log , it also write down the current time and date so that I can more easily to trace the error , can advise what can i do ?


2. I have a ftp script to a file as below

ftp ip <cd /tmp
mput *
bye
EOF

it is OK , it ftp all files to /tmp , but if I want to log down all file name that HAVE transferred , can advise what can i do ? thx
8 REPLIES 8
Steven Schweda
Honored Contributor

Re: About shell script

1. How about this?:

date >> /tmp/comp_log
haeman
Frequent Advisor

Re: About shell script

date >> /tmp/comp_log seems not work

the comp would write the error when have difference and do not write anything when no difference , I only want it write down the time when have error , what can i do ? thx
Shrikant Lavhate
Esteemed Contributor

Re: About shell script

Hi,

for that you can check exit status (echo $?) of comp process and accordingly you append/not date output in log file!
Will it remain a personal, if I broadcast it here!
haeman
Frequent Advisor

Re: About shell script

thx reply ,

it is OK for my first problem , but I can't solve the second problem , please help , thx
Cem Tugrul
Esteemed Contributor

Re: About shell script

if i understand u correctly about the 2nd q
try to write something on the top of your ftp script like;
#!/usr/bin/ksh
exec 1>/tmp/ftp_transferlog 2>&1
set -o xtrace
Good Luck,
Our greatest duty in this life is to help others. And please, if you can't
James R. Ferguson
Acclaimed Contributor

Re: About shell script

Hi:

If you want to log the files transfered, capture the session's dialog in a log file and parse the output. Change your script, as posted, to look like:

#!/usr/bin/sh
typeset LOG=/var/tmp/output.$$
ftp -inv<> ${LOG}
cd /tmp
mput *
bye
EOF!
echo "See: '${LOG}'"

Regards!

...JRF...
haeman
Frequent Advisor

Re: About shell script

thx reply ,

I tried Cem Tugrul and James R. Ferguson 's method , it can log all process that in the ftp process , what I would like is to log the transferred file only , not the messages of the transfer process , can advise what can i do ? thx


log
=======
Connected to 192.168.0.1
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
Interactive mode on.
Passive mode off.
530 Please login with USER and PASS.
Local directory now /ora
530 Please login with USER and PASS.
mput aaa? 530 Please login with USER and PASS.
mput bbb? 530 Please login with USER and PASS.
mput ccc? 530 Please login with USER and PASS.
Please login with USER and PASS.
Please login with USER and PASS.
"
"
James R. Ferguson
Acclaimed Contributor

Re: About shell script

Hi (again):

> what I would like is to log the transferred file only , not the messages of the transfer process

What's so hard about parsing the output file of the FTP, as I suggested, and logging (appending) successful transfer information to a *separate* log?

Regards!

...JRF...