VMware Cloud Community
BlobZ
Contributor
Contributor

Question regarding run-parts and cron jobs

Hi,

I have created the script shown below to backup my VMWare installation and added the script to the cron.daily directory. It runs daily as part of the other cron jobs.

However the output it generates is about 55MB whereas if I run the script when logegd on as root it generates about 700MB.

I'm confused about why there is a difference. Does anyone have any ideas.

Thanks.

Bob

#!/bin/sh

SHELL=/bin/bash

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin

mount -t smbfs -o username=domain
userid,password=password //server/d$ /mnt/backup

tar -czf /mnt/backup/vmbackup/console/service-console-daily.tar.gz --exclude /proc --exclude /vmfs --exclude /lost+found --exclude /tmp --exclude /mnt /

umount /mnt/backup

Tags (4)
0 Kudos
5 Replies
Texiwill
Leadership
Leadership

Hello,

Add to the script some debugging:

add to the top

 set -x

and change the tar options to be

-czvf

Find out what it is doing, it could be stopping early for some reason or not doing as you expect when run from cron. Remember cron based scripts do not run as a user per say, so there is no controlling terminal, etc.


Best regards,

Edward L. Haletky

VMware Communities User Moderator

====

Author of the book 'VMWare ESX Server in the Enterprise: Planning and Securing Virtualization Servers', Copyright 2008 Pearson Education.

CIO Virtualization Blog: http://www.cio.com/blog/index/topic/168354

As well as the Virtualization Wiki at http://www.astroarch.com/wiki/index.php/Virtualization

--
Edward L. Haletky
vExpert XIV: 2009-2023,
VMTN Community Moderator
vSphere Upgrade Saga: https://www.astroarch.com/blogs
GitHub Repo: https://github.com/Texiwill
0 Kudos
BlobZ
Contributor
Contributor

Ed,

Thanks for the feedback. I can see that this will give me more outoput but how do I see that output? Is there somewheer that the verbose message for the script are logged?

Sorry I'm not a LInux expert at all!

Bob

0 Kudos
pti_loup
Enthusiast
Enthusiast

Hi Bob!

After implementing Ed's suggestions, you could redirect the output of your cron job to <file1> by modifying your crontab entry :

myPath/myScript > /tmp/file1

Then run your job script manually redirecting its output to <file2> :

myPath/myScript > /tmp/file2

and then see where the differences come from using :

diff /tmp/file1 /tmp/file2 | less

Probably there's something like an access rights issue that limits the backup scope when it's run as a cron job...

Best regards,

Pascal.

0 Kudos
kjb007
Immortal
Immortal

If you're running into an error, you'll need to redirect the STDERR as well as STDOUT. The below update will send your output as well as any errors encountered to /tmp/file1

myPath/myScript > /tmp/file1 2>&1

-KjB

vExpert/VCP/VCAP vmwise.com / @vmwise -KjB
0 Kudos
Texiwill
Leadership
Leadership

Hello,

Since your file is in cron you should receive an email message with the output. If you check the mail on the ESX server you will find it. To implement the suggested statements, if you placed the script in /etc/cron.daily you will need to wrap the script within another script.... I.e.

mv /etc/cron.daily/scriptname /root/scriptname
chmod ugo+x /root/scriptname
cat > /etc/cron.daily/newscriptname << EOF
#!/bin/bash
/root/scriptname >& /tmp/logfilename
EOF

This way when the script runs stderr and stdout will both be redirected to /tmp/logfilename.


Best regards,

Edward L. Haletky

VMware Communities User Moderator

====

Author of the book 'VMWare ESX Server in the Enterprise: Planning and Securing Virtualization Servers', Copyright 2008 Pearson Education.

CIO Virtualization Blog: http://www.cio.com/blog/index/topic/168354

As well as the Virtualization Wiki at http://www.astroarch.com/wiki/index.php/Virtualization

--
Edward L. Haletky
vExpert XIV: 2009-2023,
VMTN Community Moderator
vSphere Upgrade Saga: https://www.astroarch.com/blogs
GitHub Repo: https://github.com/Texiwill
0 Kudos