Results 1 to 2 of 2
Hello,
I have a script that connects to a windows server, downloads a file, appends to it and then re-uploads the updated file.
I want to implement error handling. An ...
- 06-01-2011 #1Just Joined!
- Join Date
- Jun 2011
- Posts
- 1
bash smb script error handling
Hello,
I have a script that connects to a windows server, downloads a file, appends to it and then re-uploads the updated file.
I want to implement error handling. An email is to be generated indicating whether there was an error or not. This email should include all standard and error output as a body. The current script looks something like this :
The reason for the grep -v's is because, from my understanding, when using smbclient, ALL output goes to stdout, even errors. For this reason, I need to filter out lines including "domain" "putting file" or "getting file", all of which aren't errors.Code:function Email_ServerSupport { for time in once; do echo "Subject: Billing - smb copy to accounting" $1 cat /tmp/smbx cat /tmp/smbxerr done | mail $EMAILADDR } /usr/bin/cp /dev/null /tmp/smbx /usr/bin/cp /dev/null /tmp/smbxerr cd /tmp /usr/sfw/bin/smbclient $LOCATION -A $AUTHFILE >>/tmp/smbx <<EOF get $OUTFILE exit EOF cat $INFILE >> $OUTFILE /usr/sfw/bin/smbxclient $LOCATION -A $AUTHFILE >>/tmp/smbx <<EOF put $OUTFILE cat /tmp/smbx | grep -v "Domain" | grep -v "putting file" | grep -v "getting file" >> /tmp/smbxerr if [ -s /tmp/smbxerr ]; then Email_ServerSupport " ERROR" exit else echo "Transfer successful." Email_ServerSupport " SUCCESS" fi
The problem is that even though the script seems to catch errors successfully now and then, the success email ends up blank (/tmp/smbx is somehow empty). I'm also worried it could miss possible errors I haven't tested.
I'm thinking it has to do with the way "EOF" functions. Is there any way to capture output from the "put" and "get" commands? I can't simply redirect the output, can I?
Any help would be greatly appreciated, I'm fairly new to scripting (I'm more of a network/security guy).Last edited by KyouKyou; 06-02-2011 at 01:22 PM.
- 06-02-2011 #2Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
try adding 2>&1 to the end of your EOF commands, e.g.:
hthCode:# ls foo >> /tmp/foo.out <<EOF 2>&1 > EOF # cat /tmp/foo.out ls: foo: No such file or directory


Reply With Quote