Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cron

Status
Not open for further replies.

sumncguy

IS-IT--Management
May 22, 2006
118
US
I have the following running in Cron.
I RESULTFILE is created and has expected content.
The mail is sent however, the attachment isnt.

I have had path issues with cron before, but Im not sure I can give any further full paths then I have already done. One side note is that the ADMINs make me sudo up to an account with a higher level of permissions than I have.
It was working fine at one point.


#! /bin/ksh
#
<run snmp script> > /store/eng/tools/monthly/RESULTFILE
sleep 500
/usr/bin/ uuencode 'RESULTFILE' /store/eng/tools/monthly/RESULTFILE |\
mailx -s "RESULTFILE" <mail.adr.1> <mail.adr.2> <mail.adr.3>
 
Why the sleep 500? Is it because the snmp script runs a child process in background and you want to wait until the file *should be* there before you try to uuencode/mail it?

If so, a first test is to double the sleep period. But it may be better to enter a sleep loop until you can ascertain the output file is complete - grep for a certain phrase in the file or so?


HTH,

p5wizard
 

Maybe you had some typo where you enter spaces in the the uuencode path, better try this:
Code:
#! /bin/ksh
#
<run snmp script>  > /store/eng/tools/monthly/RESULTFILE
sync;sync;
/usr/bin[b][red]/uuencode[/red][/b] 'RESULTFILE' [b][red]<[/red][/b]/store/eng/tools/monthly/RESULTFILE |\
mailx -s "RESULTFILE" <mail.adr.1> <mail.adr.2> <mail.adr.3>
[3eyes]
PS: Also notice the redirection (<) in the uuencode.

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
uuencode does accept two parameters, but they are reversed:

uuencode --help said:
Usage: uuencode [INFILE] REMOTEFILE

So try:

Code:
/usr/bin/uuencode /store/eng/tools/monthly/RESULTFILE RESULTFILE |\

Although LKBrwnDBA's suggestion should work too.

Annihilannic.
 
I do a


SunOS xxxxx 5.8 Generic_117350-28 sun4u sparc SUNW,Sun-Fire-V440

~> echo $SHELL
/usr/local/bin/zsh

Cant find out the default shell for superman.

To get to cron I do ..

sudo -u superman crontab -e
enter my password and crontab opens


The second set of commands does work without a problem from my command line but not cron.
The first set of commands does work without a problem from both command line and cron.

Why ?


/usr/bin/uuencode 'houseboat' < /some/place/houseboat |\
mailx -s "houseboat" sumguys@email.addy


/usr/bin/uuencode 'houseboat'| /some/place/houseboat |\
mailx -s "houseboat" sumguys@email.addy

Thanks
 
I guess that cron spawn sh (bourne shell) instead of zsh ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

Thanks the redirect works.

What exactly does sync do. I read man but it really didnt give me too much and I didnt understand what it was telling me.

Ive also looked through my Nutshell book. Aint in thar !!

Thanks
 
In my opinion the syncs suggested above are unnecessary. It ensures that all information cached in memory but not yet written to disk is written. The only time I would have used it in the past was immediately before resetting a system (i.e. not doing a clean shutdown).

Annihilannic.
 
The reason why Im asking is I have an abnormality occuring.

I need to actual run this snmp script 4 times (because of the number of network devices Im hitting). Then send email accordingly he is the exact script with names changed to protect the innocent.

I get all the emails but the first attachment is not included but is under the proper directory with 777 perms.
The actual format is a bit hosed as shown ... /bin/ksh commented out because it didnt play nice under ksh. The script is running fine. The files are there. Again, the specific problem is that the first email is sent without the attachment (file is present)

Any help would be very much appreciated. Im stumped and unfortunately, not alot of unix gurus around.

# #! /bin/ksh
#
rm /store/eng/tools/monthly/R*.csv
#
touch /store/eng/tools/monthly/R5515ce1.csv
touch /store/eng/tools/monthly/R5515ce2.csv
touch /store/eng/tools/monthly/Rtroyce1.csv
touch /store/eng/tools/monthly/Rtroyce2.csv
#
chmod 777 /store/eng/tools/monthly/R5515ce1.csv
chmod 777 /store/eng/tools/monthly/R5515ce2.csv
chmod 777 /store/eng/tools/monthly/Rtroyce1.csv
chmod 777 /store/eng/tools/monthly/Rtroyce2.csv
#
/store/eng/tools/monthly/DCWA -c XXX -f /store/eng/tools/monthly/dcwA > /store/eng/tools/monthly/R5515ce1.csv
sleep 600
/usr/bin/uuencode 'R5515ce1.csv' < /store/eng/tools/monthly/R5515ce1.csv |\
mailx -s "R5515ce1.csv dcwA" XXXX@XXX.COM
#
/store/eng/tools/monthly/DCWB -c XXX -f /store/eng/tools/monthly/dcwb > /store/eng/tools/monthly/R5515ce2.csv
sleep 600
/usr/bin/uuencode 'R5515ce2.csv' < /store/eng/tools/monthly/R5515ce2.csv |\
mailx -s "R5515ce2.csv dcwb" XXXX@XXX.COM
#
/store/eng/tools/monthly/DCEA -c XXX -f /store/eng/tools/monthly/dceA > /store/eng/tools/monthly/Rtroyce1.csv
sleep 600
/usr/bin/uuencode 'Rtroyce1.csv' < /store/eng/tools/monthly/Rtroyce1.csv |\
mailx -s "Rtroyce1.csv dceA" XXXX@XXX.COM
#
/store/eng/tools/monthly/DCEB -c XXX -f /store/eng/tools/monthly/dceb > /store/eng/tools/monthly/Rtroyce2.csv
sleep 600
/usr/bin/uuencode 'Rtroyce2.csv' < /store/eng/tools/monthly/Rtroyce2.csv |\
mailx -s "Rtroyce2.csv dceb" XXXX@XXX.COM

 
Are you redirecting the output of this script to a log file? Anything in there?

Try putting an ls -l of each file in the script just before the uuencode step perhaps?

Annihilannic.
 


Instead of sleep 600 use sync; sync.

The sync command will 'synchronize' (write) buffers in memory to disk.

From manual said:
sync() first commits inodes to buffers, and then buffers to disk.

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Yes, but why would you want to do that? It's not like the subsequent uuencode command could bypass those buffers to read from disk before any data was committed?

Annihilannic.
 
sumncguy said:
. . . the specific problem is that the first email is sent without the attachment (file is present)

Strange, I made the folowing test and it does e-mail an empty file:
Code:
$ touch test1
$ chmod 777 test1
$ ls -alp test1
-rwxrwxrwx   1 oracle   dba            0 Jan  5 14:41 test1
$ uuencode 'test1' <test1|mailx -s'test1' oracle@xxxxx.com
[ponder]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 

No Annihilannic .. the scripts are identical with the exception of the actual content of the ascii files I refer to. The file is there.

To test, heres what I did ..

I set up the script in cron to run in the next minute.
I sat there at /store/eng/tools/monthly doing ls -l *.csv
Until I saw the file created and content being written.

This is crazy man !! If I run it as myself from the command line it works. What the heck ??!!!!
 
I agree, it's freaky, but there has to be an explanation.

Try changing this:

Code:
/usr/bin/uuencode 'R5515ce1.csv' < /store/eng/tools/monthly/R5515ce1.csv |\
mailx -s "R5515ce1.csv dcwA" XXXX@XXX.COM

to this:

Code:
/usr/bin/uuencode 'R5515ce1.csv' < /store/eng/tools/monthly/R5515ce1.csv > /store/eng/tools/monthly/R5515ce1.uue

mailx -s "R5515ce1.csv dcwA" XXXX@XXX.COM < /store/eng/tools/monthly/R5515ce1.uue

And check whether the UUE file is produced.

Also, do you have a way to temporarily prevent the email from being delivered? i.e spoof your email gateway in /etc/hosts, or stop your MTA (sendmail/postfix/etc.)? If so, do that as well, and then examine the mail files created in /var/spool/mqueue or wherever your MTA stores them to make sure that the attachment has actually been included... maybe it is being stripped off by your email gateway for some reason? Alternatively change the destinatino email address to a local user name so it doesn't go to your gateway at all.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top