Hi guys,
I got my whole environment up and running, I can manually create backups with ghettoVCBg2.pl and it works perfectly.
Only thing I want to do now, is make it a cronjob.
I tested the cron feature with adding a simple task in /etc/crontab:
*/1 * * * * root wall test
this works fine, every minute I get the message "test" in my console.
I can also add this to /etc/crontab:
*/1 * * * * root /home/vi-admin/test.sh
I made the file test.sh, this is what's in the file:
wall test
again, I get the message "test" in my console.
Now the problem...
When I edit /etc/crontab with this:
*/1 * * * * root /home/vi-admin/ghettoVCBg2.pl --vmlist nag001 --dryrun 1
nothing executes, I als tried to put the command ./ghettoVCBg2.pl --vmlist nag001 --dryrun 1 in a file called test.sh... after that I edited /etc/crontab with:
*/1 * * * * root /home/vi-admin/test.sh
again, nothing executes.
When I look at "sudo nano /etc/crontab" I see:
crond[12611]: (root) CMD (/home/vi-admin/test/sh)
crond[12611]: pam_sm_acct_mgmt failed
crond[12611]: pam_sm_close_session error
btw: I also tried to edit /etc/crontab with:
*/1 * * * * vi-admin /home/vi-admin/test.sh
and
*/1 * * * * vi-admin /home/vi-admin/ghettoVCBg2.sh --vmlist nag001 --dryrun 1
I'm out of knowledge here...
Tnx in advance
Jim
seemingly i was able to repeat problem and resolve it
Edit backup.sh (script for start from cron) in the following manner
#!/bin/bash # LD_LIBRARY_PATH=/opt/vmware/vma/lib64:/opt/vmware/vma/lib export LD_LIBRARY_PATH PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/java/jre-vmware/bin:/sbin:/usr/sbin:/home/vi-admin/bin export PATH cd /home/vi-admin/ /home/vi-admin/ghettoVCBg2.pl --vmlist list --dryrun 1
If execution by "sudo backup.sh" will complete without error, you can insert call backup.sh to crontab
Hi,
Usually, the cause for scripts that run pretty well with a normal user account and produce errors while running in a crontab is a difference in the environment.
You can see your actual environment with the following command:
$ set
The solution is that you can add environment variables in your crontab file.
See for more information: http://linuxshellaccount.blogspot.com/2007/10/crontab-and-your-environment.html and http://adminschoice.com/crontab-quick-reference
Paul Grevink
If you find this information useful, please award points for "correct" or "helpful".
I normally edit crontab via crontab -e. You may also want to send the output of the script somewhere to see what is actually happening. You can do this via:
*/1 * * * * root /home/vi-admin/ghettoVCBg2.pl --vmlist nag001 --dryrun 1 >> /root/myTest.out 2>&1
Let it run and then look at /root/myTest.out to see the output that is happening.
If you found this at all helpful please award points by using the correct or helpful buttons! Thanks!
Both not working guys,
strange thing is I can't get a myTestlog.out ? ? ?
als tried to put the log in /home/vi-admin (to be sure it can write there)
...
I'm stuck!
Try this:
*/1 * * * * /home/vi-admin/ghettoVCBg2.pl --vmlist nag001 --dryrun 1 >> /home/vi-admin/myTest.out
Then you should see myTest.out in /home/vi-admin.
If you found this at all helpful please award points by using the correct or helpful buttons! Thanks!
seems logical to me, but no log,
I also added the line
*/1 * * * * wall cron running
to see if the cron deamon is doing something...
If you are using crontab -e to edit then it should HUP cron. If not, then you might want to sudo /etc/init.d/crond restart to make sure it is
If you found this at all helpful please award points by using the correct or helpful buttons! Thanks!
I'm am adding the lines you told me like this:
sudo nano /etc/crontab
#esx backup
*/1 * * * * /home/vi-admin/ghettoVCBg2.pl --vmlist nag001 --dryrun 1 >> /home/vi-admin/myTest.out
#crontest
*/1 * * * * wall cron running
So I am not using crontab -e
To give you some more details,
----
/home/vi-admin
ghettoVCBg2 ghettoVCBg2.pl nag001
----
----
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=vi-admin
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
#cronjob esx backup
*/1 * * * * root /home/vi-admin/ghettoVCBg2.pl --vmlist nag001 --dryrun 1
#cronjob test
*/1 * * * * root wall cron running
----
Now when I save the above crontab file, wait for 1 minute, and got this output:
----
Broadcast message from root (Thu Oct 28 10:01:01 2010):
cron running
----
Oct 28 10:01:01 vma002 crond[18555]: (root) CMD (wall cron loopt)
Oct 28 10:01:01 vma002 crond[18552]: pam_sm_close_session error
Oct 28 10:01:01 vma002 crond[18553]: pam_sm_open_session failed [error code: 2]
Oct 28 10:01:01 vma002 crond[18557]: (root) CMD (/home/vi-admin/ghettoVCBg2.pl --vmlist nag001 --dryrun 1)
Oct 28 10:01:01 vma002 crond[18554]: pam_sm_open_session failed [error code: 2]
Oct 28 10:01:01 vma002 crond[18558]: (root) CMD (run-parts /etc/cron.hourly)
Oct 28 10:01:01 vma002 crond[18554]: pam_sm_close_session error
----
The script "ghettoVBCg2.pl" doesnt work... I don't know what the problem is.
try execute (without cron)
cd /
sudo /home/vi-admin/ghettoVCBg2.pl --vmlist nag001 --dryrun 1
Are there any errors?
Yup errors indeed,
$ sudo /home/vi-admin/ghettoVCBg2.pl --vmlist nag001 --dryrun 1
Password:
Can't load '/usr/lib/perl5/site_perl/5.8.8/libvmatargetlib_perl.so' for module vmatargetlib_perl: libtypes.so: cannot open shared object file: No such file or directory at /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/DynaLoader.pm line 230.
at /usr/lib/perl5/site_perl/5.8.8/VMware/VmaTargetLib.pm line 10
Compilation failed in require at /usr/lib/perl5/site_perl/5.8.8/VMware/VIFPLib.pm line 10.
BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.8/VMware/VIFPLib.pm line 10.
Compilation failed in require at /home/vi-admin/ghettoVCBg2.pl line 19.
BEGIN failed--compilation aborted at /home/vi-admin/ghettoVCBg2.pl line 19.
If you get error, take a look post lamw in thread "Need some help with my cron-fu..."
and create shell script which set env variables LD_LIBRARY_PATH & path and execute you perl script
I'm not that deep into Linux,
can you give me an example ?
#!/bin/bash # LD_LIBRARY_PATH=/opt/vmware/vma/lib64:/opt/vmware/vma/lib PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/java/jre-vmware/bin:/sbin:/usr/sbin:/home/vi-admin/bin /home/vi-admin/ghettoVCBg2.pl --vmlist nag001 --dryrun 1
If this script executed over sudo without error, you can try execute it over crond
I tried it with:
*/1 * * * * root /home/vi-admin/test.sh <= test.sh being your script (wich worked when run alone)
but in the crontab, it doesnt run.
Also tried:
SHELL=/bin/bash
PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/java/jre-vmware/bin:/s$
LD_LIBRARY_PATH=/opt/vmware/vma/lib64:/opt/vmware/vma/lib
MAILTO=vi-admin
HOME=/
run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
#cronjob esx backup
*/1 * * * * root /home/vi-admin/ghettoVCBg2.pl --vmlist nag001 --dryrun 1
#cronjob test
*/1 * * * * root wall cron running
doesnt work...
1. Restore the original state of the crontab
2. About my script executed by sudo - Are there any errors?
Yup errors indeed,
vi-admin@vma002 ~$ cd /
vi-admin@vma002 /$ sudo /home/vi-admin/ghettoVCBg2.pl --vmlist nag001 --dryrun 1
Password:
Can't load '/usr/lib/perl5/site_perl/5.8.8/libvmatargetlib_perl.so' for module vmatargetlib_perl: libtypes.so: cannot open shared object file: No such file or directory at /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/DynaLoader.pm line 230.
at /usr/lib/perl5/site_perl/5.8.8/VMware/VmaTargetLib.pm line 10
Compilation failed in require at /usr/lib/perl5/site_perl/5.8.8/VMware/VIFPLib.pm line 10.
BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.8/VMware/VIFPLib.pm line 10.
Compilation failed in require at /home/vi-admin/ghettoVCBg2.pl line 19.
BEGIN failed--compilation aborted at /home/vi-admin/ghettoVCBg2.pl line 19.
vi-admin@vma002 /$
create test1.sh - touch test1.sh
edit test1.sh - (for example vi test1.sh)
#!/bin/bash # LD_LIBRARY_PATH=/opt/vmware/vma/lib64:/opt/vmware/vma/lib PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/java/jre-vmware/bin:/sbin:/usr/sbin:/home/vi-admin/bin /home/vi-admin/ghettoVCBg2.pl --vmlist nag001 --dryrun 1
try to execute over sudo
sudo ./test1.sh
Are there any errors?