Cron Job Help
Hello everyone,
I'm trying to make a cron job work but I'm having the toughest time with "crontab -e". When I enter crontab -e it takes me to my vi editor and lists the default cron jobs (hourly, daily, etc). I've tried to go to the last line and add a new * * * * * "file path" formatted line. I've tried editing the existing lines but the result is always the same. No matter what I do in crontab -e it tells me that it's a read-only file system. How can I overcome this and get some cron jobs working? Also, if I ever do get a crontab editor working... I feel comfortable with the first part of the cron line format (* * * * *) but not too comfortable with the path info. I can run the script from root as ./filename and it runs just fine so what syntax would go in the path line... just the filename or ./filename?? Thanks for any help with this. iz |
1. If you want to run a cron job as yourself, non-root, then run crontab -e as yourself (not root). That should solve your permissions problem.
If you want to run it as root, do it from the root acct. If you've still got the above problem, show us your /etc/fstab file: ll /etc/fstab cat /etc/fstab its possible that partition is mounted read-only 2.: in cron, always use full path to all your progs and any progs/files that they call. The default cron env is minimal. 3. If cron has a problem, it'll normally email root and or the owning user. |
You can set the editor of choice with the VISUAL environment variable if you are not feeling comfortable with vi.
Code:
export VISUAL=nano |
Need more info
Chris,
first, thanks for trying to help. 1. How do I run it as my self? As far as I know, I've been running it from the root. That is, after boot up I'm not changing any directories. Are you saying that i need to "cd /usr...something??" Sorry, I'm really not tracking. What do you mean by root acct? I've been searching for hours and all the info I find on this stuff assumes that I already know how to tell when I'm in the "root" or how to be in my "user" tree/directory. How do you get a reference for where you currently are in the tree structure? 2. Okay, from start up and without changing any directories with cd (i'm assuming that's "root") I can run my script with ./scriptname. So, if that's in the root directory, what is the actual syntax in the cron? Is it ./scriptname or /scriptname?? 3. I'm not interested in mail. My linux box is strictly a remote client that I'm controlling from a local server. It does nothing more than serve as a bulletin board. I'm just trying to get it set up to do a few things on a timed schedule. Thanks again, iz 1. If you want to run a cron job as yourself, non-root, then run crontab -e as yourself (not root). That should solve your permissions problem. If you want to run it as root, do it from the root acct. If you've still got the above problem, show us your /etc/fstab file: ll /etc/fstab cat /etc/fstab its possible that partition is mounted read-only 2.: in cron, always use full path to all your progs and any progs/files that they call. The default cron env is minimal. 3. If cron has a problem, it'll normally email root and or the owning user. __________________ Cheers Chris |
Quote:
Let's start at a more basic level: How are logging into the system, and what crontab do you want to edit? One way to answer the second question is to decide if you will need super-user privileges for any of the things you want the crontab to run. |
Quote:
I want to edit ANY crontab that is not exclusive to any users. I want it to be a function common to the system and NOT exclusive to any user. I want the cron to run as soon as the Linux client has power. Without loggin in, I sit at the local Linux client and turn it on. From there, I press ctrl-alt-5 to open a linux command prompt interface. From there, I've been able to create a script that I'm trying to work into a cron that runs as soon as the box comes on... not specific to any user but common to all users. Also, I don't know if this helps but... The preface to the command prompt cursor when I boot up and open the Linux command prompt interface is: sh-3.2# |
Quote:
Thanks for that. |
It would help a lot if you told us which distribution & version of Linux you've got.
Its very unusual not to have to login... However, the prompt ending in '#' usually means you are logged in as root user. This is the equivalent to the admin user (aka 'god') in MS. You can check by using the cmd whoami at the cmd line. When I mentioned mail, what I meant was that usually an email server is running internally, which various services, inc cron, use to send notices to users, inc root, if an error occurs. Also, sometimes just for information. It won't normally be configured to send email externally to other systems. You can check by issuing the cmd mailx Or at the cmd line. cron is a system service that is start by the OS at boot time and runs forever. If you want a job to be repeated indefinitely at set intervals, that is the right tool. If you only want a job run once at boot time, let us know, as its a different technique altogether. To find out what directory you are in, use the cmd pwd Do that in the dir your script is in. Post the contents of your script. As above we need you to run the cmds ls -l /etc/fstab cat /etc/fstab Post the results of all the cmds I've mentioned, so we can see them. You really need to bookmark/read this: http://rute.2038bug.com/index.html.gz |
sh-3.2# is at command prompt so I assume that is the version?
whoami = root pwd = / mail/mailx = command not found... and I don't care about mail. "cron is a system service that is start by the OS at boot time and runs forever. If you want a job to be repeated indefinitely at set intervals, that is the right tool." Yes, this is what I want. script I want cron to run: ping -c 15 123.45.678.910 if [ $? -ne 0 ] then echo $? shutdown -r -t 10 now fi ls -l /etc/fstab = -rw-r--r-- 1 root root 3301 2008-10-26 18:07 /etc/fstab cat /etc/fstab = Well, I'm going to have to wait until tomorrow to get a flash drive so i can transfer over the text file I couldn't open: http://rute.2038bug.com/index.html.gz Thanks again, Iz |
Quote:
Code:
uname -a Quote:
|
uname -a = Linux 001cc040e18b 2.6.26-ARCH #1 SMP PREEMPT...
So anyone have some actual help with this? |
Your script:
Code:
ping -c 15 123.45.678.910 cron has no stdout/stderr and a minimal environment. The ping command wants to echo to stdout and/or stderr, neither of which are available to cron. In most cases, babble from scripts invoked by cron is sent by mail to the crontab's owner (in this case, root). Try redirecting stdout and stderr to a file, then reading from that file to determine whether to invoke the shutdown command. Have you solved the permissions problem with the editor? |
Quote:
(Off-topic: I'm having a very hard time understanding your set up: you apparently have a box with Arch Linux on it, the machine allows direct-to-root logins with no password (?!?), and you're running it with a pretty limited sense of how *nix systems work. How exactly did you get into this situation?) |
lol, well i'm currently trying to figure out why I can't even get my flash drive to work. I plug it in, do lsusb and can see a flash drive but i can't seem to access it. My fstab doesn't include anything about usb so i think i'm gonna try to load a line into the fstab and see if that helps.. then maybe i can get my fstab over here.
Is there anything else in particular that I should have in my fstab that would let me do stuff with cron? |
Woo, i'm getting marginally better at this. Here's the fstab (I just now added the /dev/sda1 /flash vfat defaults 0 0 part to get my flash drive working lol):
# glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for # POSIX shared memory (shm_open, shm_unlink). # (tmpfs is a dynamically expandable/shrinkable ramdisk, and will # use almost no memory if not populated with files) # Adding the following line to /etc/fstab should take care of this: none /tmp tmpfs defaults 0 0 none /lib/splash/cache tmpfs defaults 0 0 none /var/log tmpfs defaults 0 0 none /var/spool/cups tmpfs defaults 0 0 none /usr/share/X11/xkb/compiled tmpfs defaults 0 0 none /var/run tmpfs defaults 0 0 none /var/tmp tmpfs defaults 0 0 none /var/lib/dhcpcd tmpfs defaults 0 0 none /root tmpfs defaults 0 0 proc /proc proc defaults 0 0 sysfs /sys sysfs defaults 0 0 none /opt/wine-root/drive_c/windows/temp tmpfs defaults 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/sda1 /flash vfat defaults 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 /dev/hda1 / ext3 defaults,noatime 0 0 |
All times are GMT -5. The time now is 04:57 PM. |