Howdy.
So here's my trouble.
I've recently upgraded to the vMA 4.1 for my environment. I have several legacy scripts that I'm working on converting to pCLI when I've got time, but for now I need to get one of them running on the vMA. Part of the script invokes vmcontrol.pl for its operation.
When I run the script as user (vi-admin) or root, it works fine. When I put the scripts into a cron job, they fail. Logging from the job shows that in the cron environment the script is unable to compile the perl files and complains about finding a shared object file. My first thought is 'ah, permissions issue', but this doesn't seem to be holding true.
I know this is something obvious and easy, but I'm just not putting the dots together. I've tried forcing path variables into the cron, I've verified this across several users, and I've done this exact same process before on the 4.0 vMA plenty of times and it worked then. I know it's an environment thing, but I just don't have enough Fu to figure it out.
So I'm asking for help. Anyone have any ideas? All inputs (And I'm working on RTFM'ing, but I figured I'd work this thread at the same time) are appreciated.
Thanks!
- Abe
Integritas!
Abe Lister
Just some guy that loves to virtualize
==============================
Ain't gonna lie. I like points. If what I'm saying is something useful to you, consider sliding me some points for it!
You're correct, its most likely the PATH is not properly set. I would recommend you run "env" when you're login as root or vi-admin and get the PATH variable and take that add that to /etc/crontab if you're trying to run it as vi-admin. One you get it working, you can figure out what paths you actually need but since you're running the vSphere SDK for Perl scripts, you want to make sure you capture all the paths that the script references.
=========================================================================
William Lam
VMware vExpert 2009,2010
VMware VCP3,4
VMware VCAP4-DCA
VMware scripts and resources at:
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
You're correct, its most likely the PATH is not properly set. I would recommend you run "env" when you're login as root or vi-admin and get the PATH variable and take that add that to /etc/crontab if you're trying to run it as vi-admin. One you get it working, you can figure out what paths you actually need but since you're running the vSphere SDK for Perl scripts, you want to make sure you capture all the paths that the script references.
=========================================================================
William Lam
VMware vExpert 2009,2010
VMware VCP3,4
VMware VCAP4-DCA
VMware scripts and resources at:
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Wow, Mr. Lam himself replies. I'm running tons of your scripts in my lab. Thank you for all that you do - you've made my life much easier. If you're ever on the east coast, I owe you a beer and a large steak at a minimum.
Agreed, pathing is probably what's killing me. I did what you suggest - copied the results of 'env' into /etc/crontab, still no joy.
I decided I was reaching for the stars a little bit and started to carve back the script a ways to better define the problem. Here's what I found that was interesting...
In my original script, one of the early lines is
source /path/I/cant/remember/vifpinit myVCserver
I've replaced that line with (due to deprecation of vifpinit):
source /absolute/path/to/vifptarget -s myVCserver
I commented the rest of the script out - and I'm still getting the same error regarding compilation and so files. This tells me that what I had originally thought was a problem with the vmcontrol.pl<http://vmcontrol.pl> invocation is actually happening higher up in my script - I'm not able to initialize/set the vCenter as the active target from a cron job. I don't know if there's a better method of doing this, but it's the method I've always used and it has worked historically.
Again, the script works fine outside of the cron environment. In the environment, it fails, even when I manually force my environmental variables into the logic that cron is using. I acknowledge plainly that my Linux fu has big holes in it, so this could easily be a user-induced problem. But I'm dangerous enough (to myself and equipment, heh heh...) that I feel confident that I didn't do anything to create this issue. Literally, I deployed the 4.1 vMA, scp'd my scripts from the old vMA where they were functioning to the new vMA, and started working on shaking the bugs out (like vifpinit), and that's how I got here.
Thanks for your insight and help bud. I'm doing some homework on cron vs. perl, (saw some interesting things over there on the cpan boards that might be worthwhile pursuits), but I'm not sure if I'm at the right circus and watching the wrong clown. Reckon we'll see...
V/r,
- Abe Lister
I'm assuming you've seen this reply - ?
I'm still not exactly clear on the errors ... what I might recommend is to redirect the script execution to a tmp file in your cron entry so you can see the errors.
e.g.
01 * * * * root /home/vi-admin/somescript.pl >> /tmp/debug.log
=========================================================================
William Lam
VMware vExpert 2009,2010
VMware VCP3,4
VMware VCAP4-DCA
VMware scripts and resources at:
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Truth told, no, I had not seen that article. I'm thinking that's just
about my problem to a T though. I have some minor deltas, but it's
nothing I can't figure on my own. Very promising. I have redirected my
errors, that's how was able to resolve my problems to the vifptarget
-and I encounter the 'alias' problem you describe. I am invoking via
source, though I use the --set vs. -s in my script. I don't think
that would be an issue, but we'll see.
I'll post success or failure tomorrow. Thanks man.
-abe
Still no joy. Here's the details - all running on a 4.1 vMA. Thoughts?
crontab -l
=============================================================
*/4 * * * root /scripts/kickoff.sh >> /var/log/kickoff.log 2>&1
more kickoff.sh
=============================================================
#!/bin/sh
lockfile=/tmp/kickoff.lck
echo "Process already running. Exiting."
exit 1
else
touch $lockfile
source /opt/vmware/vma/bin/vifptarget -s vc.core.local > /dev/null 2>&1
echo "--
"
rm -f $lockfile
fi
done
Results (from kickoff.log)
=============================================================
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 /opt/vmware/vma/sbin/touchSession.pl line 12.
BEGIN failed--compilation aborted at /opt/vmware/vma/sbin/touchsession.pl line 12.
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 /opt/vmware/vma/sbin/touchSession.pl line 12.
BEGIN failed--compilation aborted at /opt/vmware/vma/sbin/touchsession.pl line 12.
-
FLAG----
Integritas!
Abe Lister
Just some guy that loves to virtualize
==============================
Ain't gonna lie. I like points. If what I'm saying is something useful to you, consider sliding me some points for it!
You're most likely missing the lib paths, since it's unable to locate the vi-fastpass libs
Try adding the PATH and LD_LIBRARY_PATH into your crontab entry
e.g.
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
=========================================================================
William Lam
VMware vExpert 2009,2010
VMware VCP3,4
VMware VCAP4-DCA
VMware scripts and resources at:
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
William,
So I cracked it, and here's how I proceeded. There are probably better ways, but this is the one that worked for me. My linux is weak-sauce.
Tried editing my /etc/crontab. Put the lines in exactly as you indicate.
Still failed. I put an 'env' in my cron task, and in the logs it shows the cron environment with no LD_LIBRARY_PATH set.
So I rewrote the cronjob to be:
*/4 * * * LD_LIBRARY_PATH=blah /path/to/script>script.log
blah being appropriate path, and it worked!
The part I don't get is I set the LD_LIB path in /etc/crontab, no joy. I passed it in the script to the cron env, no joy. Guess I just need to figure out environments in cron...
In closing of this probably needless thread, the moral of the story is that the operator needs to go study his linux and brush up on his environments knowledge.
Thanks for all of your help man. Twitter has it that you've got cool things coming, always looking forward to seeing your latest and greatest.
Regards,
- abe