Operating System - HP-UX
1753914 Members
8969 Online
108810 Solutions
New Discussion юеВ

Explain some script lines to me please.

 
SOLVED
Go to solution
SM_3
Super Advisor

Explain some script lines to me please.

1) with the line:
mount -p | grep -E '/snapshot' > /dev/null

Why put the stdout to /dev/null? Is it in case the mount command fails?

same here:

mt -t $TAPE rew 2> /dev/null

Will this mt command produce a stderr? Or is it in case the command fails?

one more please

2) mailx -ms "`hostname` `date` Oracle Backup FAILED" < /dev/null $MAILADDRESS

Why is there input from /dev/null?

Thanks.

I don't want to create a tutorial on scripting on this forum but the curiosity is killing me!
4 REPLIES 4
curt larson_1
Honored Contributor

Re: Explain some script lines to me please.

mount -p | grep -E '/snapshot' > /dev/null

Why put the stdout to /dev/null? Is it in case the mount command fails?

well, it is going to be hard to explain one line of a script without the context it is being used.

but in this case the grep command will output the lines that it does match. it would guess that the script isn't interested in which lines match, i.e. dump the output, and is concerned with weather there is a match or not. in which the case the next lines of the script probably test the return code of the grep command. true if there is a match, false if there isn't. And, if the grep command does send something to stderr it will be output.
curt larson_1
Honored Contributor
Solution

Re: Explain some script lines to me please.

mt -t $TAPE rew 2> /dev/null

Will this mt command produce a stderr?
yes the command could produce an output to stderr, just that the error is never going to be seen or used.

Or is it in case the command fails?

without context it can't be determined. one would suppose that stderr is sent to dev/null because whoever wrote the script thought it wasn't necessary for the message to be output.

the mt command can be used in many ways. the script could be just taking a precaution to always rewind the tape before a backup. spending a few seconds rewinding a tape that is already rewound, isn't as time consuming as trying to restore from a tape with multiple volumes written to it.

then again the script could be rewinding the tape to see if the device is ready. in which case the error message isn't needed by the script, just weather the command succeeded or not. in which case the script will test the return code of the command, not what the error message was.
curt larson_1
Honored Contributor

Re: Explain some script lines to me please.

2) mailx -ms "`hostname` `date` Oracle Backup FAILED" < /dev/null $MAILADDRESS

Why is there input from /dev/null?

mailx requires a mail message. you can't just mail a subject line. so to specify an emmpty file you use /dev/null. it is easier then creating a empty file to specify for the mail message then removing it
SM_3
Super Advisor

Re: Explain some script lines to me please.

Thanks.

The script does check for the return code! i.e. by using $?

For the mailx thanks for clearing that one up.