1834149 Members
2244 Online
110064 Solutions
New Discussion

Re: Log the process

 
hanyyu1
Advisor

Log the process

I run the below command on the unix shell,

mv /tmp/abc /tmp1/ >> /tmp/abc.log

but no matter the process is success or not , it still no message write to the log ( eg. no such file ) , if I want to log what file has been moved , what can I do ? thx
3 REPLIES 3
Arunvijai_4
Honored Contributor

Re: Log the process

You need to write your own shell script with log messages based on success or failure from $? Or, you can use redirect mv /tmp/abc /tmp1/ 2>&1 /tmp/abc.log

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Muthukumar_5
Honored Contributor

Re: Log the process

>> is saying that it will log only STDOUT messages to /tmp/abc.log (appending).

If you want to capture standard output and as well as standerr messages then,

# mv /tmp/han-muthu /tmp1/ 1>>/tmp/abc.log 2>&1

which adds error messages also.

now /tmp/han-muthu file will not be there and it will make entry in that file.

To check operation success then,

echo ${?}

if 0 then success else it is failure. see relative man page with RETURN values part.

hth.
Easy to suggest when don't know about the problem!
Sivakumar TS
Honored Contributor

Re: Log the process

Hi,

while redirecting standard output / error the convention is to use
1>> for redirecting the standard output
2>> for redirecting the standard error

in your case if you want to log the error msg ( no such file) to the abc.log , we have to use

#mv /tmp/abc /tmp/1 2>> /tmp/abc.log

This will redirect the error ( which is displayed in console ) to the abc.log

The same time if you want redirect the output(otherthan error messages) like output of #ls command etc, we have to use

#ls 1>> /tmp/abc.log

in this case the output will be redirected to abc.log instead of getting displayed on the console.

With Regards,

Siva.
Nothing is Impossible !