Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Ubuntu 8.04


  • Please log in to reply

#1
jaxisland

jaxisland

    Member 1K

  • Member
  • PipPipPipPip
  • 1,703 posts
So I have a shell script that I need to run on a schedule. Manually running the file works so I know that part is fine. What Im having problems with is getting a cron job to run it.

So I have typed: crontab -e
Here is the contents:
# m h dom mon dow command
23 16 * * * /home/bob/Desktop/stopvm.sh

Right now I am trying to test the file so I used * * * so it is suppose to run everyday all year. I set the the time to 4:23 pm but I just change the time to 2 minutes ahead so I can test it. Nothing happens at the specified time. I am looking for someone to walk me through getting this running.

Thanks
  • 0

Advertisements


#2
Titan8990

Titan8990

    Member

  • Member
  • PipPipPipPipPip
  • 2,189 posts
Mind posting the script? Some things in scripts don't run correctly in cron like they do in manual runs.
  • 0

#3
jaxisland

jaxisland

    Member 1K

  • Topic Starter
  • Member
  • PipPipPipPip
  • 1,703 posts
#!/bin/sh
cd /usr/bin
vmware-cmd -H 192.168.34.3 --username root --password password1 /vmfs/volumes/Temp/XPTemp/XPTemp.vmx start soft

This is for starting a VM in ESXi. I also have a stop one as well. I cannot get either to run automatically.
  • 0

#4
jaxisland

jaxisland

    Member 1K

  • Topic Starter
  • Member
  • PipPipPipPip
  • 1,703 posts
Alright I finally figured it out.
First step is to create a file, I made mine in /home/bob
I named it crontab_file
I added the entries like:
* * * * * sh /home/bob/Desktop/stopvm

Closed the file and ran:
sudo crontab -u bob crontab_file

I verifed it was listed by using:
crontab -l

After that it ran every minute like it was suppose to. From here I am changing the schedule to something less frequent but at least its working. :)
  • 0

#5
Titan8990

Titan8990

    Member

  • Member
  • PipPipPipPipPip
  • 2,189 posts
So it was the addition of the interpreter in your cron job? Was your shebang not being read correctly?
  • 0

#6
jaxisland

jaxisland

    Member 1K

  • Topic Starter
  • Member
  • PipPipPipPip
  • 1,703 posts
3 things I did wrong:
1) i tried using crontab -e instead of creating the file and using the crontab command
2) i didnt put the "sh" in front of the path
3) cron does not like file extensions so i removed the".sh" from my file name

Oh and FYI for anyone, Ubuntu 8.10 and VMWare Remote CLI are not compatible. There are major issues with Perl. I just had to redo my ubuntu box after the upgrade. So just something if anyone comes across it. I will be using a test virtual machine before I do any major upgrades, you know like your suppose to :)


Crazy stuff, it works so good though. Im definitely a happy camper. Thanks for the help.
  • 0

#7
Titan8990

Titan8990

    Member

  • Member
  • PipPipPipPipPip
  • 2,189 posts
Good to hear you got it fixed. I have not ran in to any issues with .sh file extensions or cron -e but whatever works.


One thing that I have found with cron scripts is they usually do not like the "cd" command. It is considered good practice to always use absolute paths. So instead of:

cd /usr/bin
vmware-cmd -H 192.168.34.3 --username root --password password1 /vmfs/volumes/Temp/XPTemp/XPTemp.vmx start soft

You would do:

/usr/bin/vmware-cmd -H 192.168.34.3 --username root --password password1 /vmfs/volumes/Temp/XPTemp/XPTemp.vmx start sof

However, this is not needed in this particular case because /usr/bin is in everyone's default PATH variable:

jordan@bourne:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

root@bourne:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin

Just in case you say anything I did not unlock my root accnt, I used sudo -i.
  • 0

#8
jaxisland

jaxisland

    Member 1K

  • Topic Starter
  • Member
  • PipPipPipPip
  • 1,703 posts
Thats a good tip. Im going to change it anyways, too many years in windows administration. Thanks again!
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP