LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-27-2008, 07:25 PM   #16
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Original Poster
Rep: Reputation: 15
Need Help


Quote:
Originally Posted by raconteur View Post
Your script:

Code:
ping -c 15 123.45.678.910
if [ $? -ne 0 ]
then
echo $?
shutdown -r -t 10 now
fi
probably won't run the way you expect when invoked by cron.

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?
No, I haven't sovled the permissions problem with the editor. That's the #1 thing I need help with at the moment.

here's what I know:

uname -a = Linux 001cc040e18b 2.6.26-ARCH #1 SMP PREEMPT...
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 =

# 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
 
Old 10-28-2008, 01:18 PM   #17
raconteur
Member
 
Registered: Dec 2007
Location: Slightly left of center
Distribution: slackware
Posts: 276
Blog Entries: 2

Rep: Reputation: 44
First off, I recommend deleting all of the redundant entries in fstab.
Though they don't cause any real harm, the entries obfuscate the file.

crontab files are, as you know, text files. In slackware and most SVR4-type directory structures, they are stored in /var/spool/cron/crontabs as the name of the user (i.e. root).

You can open and edit that file with the editor of your choice, bypassing crontab -e. If the editor reports a read-only file system (details are important here... if it reports a read-only file, this doesn't apply) then it is likely that the / or /var partition is mounted read-only, though there are no indications that it should be, looking at your fstab.

crontab -e does a couple of things, it invokes the editor and loads the crontab file, and when the crontab file is closed then (if the file differs from that on disk), it also creates a trigger file in the crontab directory, usually named cron.update, and places the name of the crontab file that has been modified in that file. This tells crond to re-read the crontab file on next invocation (up to 60 seconds later) and adjust its behavior accordingly. crond then deletes the cron.update file.

If you manually edit the crontab file, the cron.update file doesn't get created and you will have to restart crond or create the cron.update file.

So, first steps... try to edit the crontab file as root. If you can't write that file, please let us know what specific error occurs when you try to write the file. If the edit is successful, then restart crond or create the cron.update file as described above.

To restart crond, find its process id with:
Code:
ps -ef | egrep crond
I usually extend that a bit to parse out just the pid of crond, but I've omitted that here. You can find find the the path and invocation arguments for crond in the init script that originally invokes it (in slackware, that's /etc/rc.d/rc.M, your installation may vary). Find that and note the invocation.

Then, kill and restart crond (again, I'm using my path and invocation arguments as an example):
Code:
kill -9 <pid>
Alternatively, you can use
Code:
killall crond
as root to avoid parsing the process tree to get the pid.

Then, restart cron using the invocation aruments for your system:
Code:
/usr/sbin/crond -l10 >>/var/log/cron 2>&1
If all of this is too confusing, you can always use the brute-force method of rebooting the machine after editing the crontab file, it will accomplish all of the same things.

The first steps here are important for us to be able to help more -- clean up the fstab file and reboot, then attempt to manually edit the crontab and tell us the specific error.

Best of luck!
 
Old 10-28-2008, 04:56 PM   #18
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Original Poster
Rep: Reputation: 15
Edited, my text was formatted just fine. The fstab is correct. brb

Last edited by grande25; 10-29-2008 at 01:15 PM.
 
Old 10-29-2008, 08:44 AM   #19
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,234

Rep: Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545
Since this task seems to be a system-wide issue, why not use /etc/crontab? That file can be edited using any editor, no need to restart cron, choice of user account to run the job.

The remarks regarding read-only file system hold of course.

jlinkels
 
Old 10-29-2008, 01:28 PM   #20
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Original Poster
Rep: Reputation: 15
Okay Raconteur

Okay, I deleted the duplicate stuff in fstab. I'm still having the same problem and I had already tried what you suggested. When I try to edit /var/spool/cron/root in nano I get an error telling me that it's a read only file system.

How do I make it a rw file system?

thanks

Quote:
Originally Posted by raconteur View Post
First off, I recommend deleting all of the redundant entries in fstab.
Though they don't cause any real harm, the entries obfuscate the file.

crontab files are, as you know, text files. In slackware and most SVR4-type directory structures, they are stored in /var/spool/cron/crontabs as the name of the user (i.e. root).

You can open and edit that file with the editor of your choice, bypassing crontab -e. If the editor reports a read-only file system (details are important here... if it reports a read-only file, this doesn't apply) then it is likely that the / or /var partition is mounted read-only, though there are no indications that it should be, looking at your fstab.

crontab -e does a couple of things, it invokes the editor and loads the crontab file, and when the crontab file is closed then (if the file differs from that on disk), it also creates a trigger file in the crontab directory, usually named cron.update, and places the name of the crontab file that has been modified in that file. This tells crond to re-read the crontab file on next invocation (up to 60 seconds later) and adjust its behavior accordingly. crond then deletes the cron.update file.

If you manually edit the crontab file, the cron.update file doesn't get created and you will have to restart crond or create the cron.update file.

So, first steps... try to edit the crontab file as root. If you can't write that file, please let us know what specific error occurs when you try to write the file. If the edit is successful, then restart crond or create the cron.update file as described above.

To restart crond, find its process id with:
Code:
ps -ef | egrep crond
I usually extend that a bit to parse out just the pid of crond, but I've omitted that here. You can find find the the path and invocation arguments for crond in the init script that originally invokes it (in slackware, that's /etc/rc.d/rc.M, your installation may vary). Find that and note the invocation.

Then, kill and restart crond (again, I'm using my path and invocation arguments as an example):
Code:
kill -9 <pid>
Alternatively, you can use
Code:
killall crond
as root to avoid parsing the process tree to get the pid.

Then, restart cron using the invocation aruments for your system:
Code:
/usr/sbin/crond -l10 >>/var/log/cron 2>&1
If all of this is too confusing, you can always use the brute-force method of rebooting the machine after editing the crontab file, it will accomplish all of the same things.

The first steps here are important for us to be able to help more -- clean up the fstab file and reboot, then attempt to manually edit the crontab and tell us the specific error.

Best of luck!
 
Old 10-29-2008, 05:51 PM   #21
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Original Poster
Rep: Reputation: 15
Can anyone help me with this? I'm getting a "read-only file system" error when I try to manually edit my root crontab (/var/spool/cron/root)

How do I overcome this?

Info:

uname -a = Linux 001cc040e18b 2.6.26-ARCH #1 SMP PREEMPT...
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 =

# 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/sda1 /flash vfat defaults 0 0
 
Old 10-30-2008, 01:37 AM   #22
raconteur
Member
 
Registered: Dec 2007
Location: Slightly left of center
Distribution: slackware
Posts: 276
Blog Entries: 2

Rep: Reputation: 44
Please type "mount" (no quotes and no arguments) on a command line and post the results. That will tell us both whether the /var file system is mounted read-only, and if it is, what the arguments to mount (or fstab) should be to mount it read-write.

As an aside, what distribution are you running?

Last edited by raconteur; 10-30-2008 at 01:38 AM.
 
Old 10-30-2008, 07:05 AM   #23
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,617

Rep: Reputation: 136Reputation: 136
123.45.678.910 is not a valid IP
 
Old 10-30-2008, 09:44 AM   #24
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 59
Quote:
Originally Posted by raconteur View Post
As an aside, what distribution are you running?
If I'm reading the output of uname -a correctly, he's running Arch Linux.
 
Old 10-30-2008, 10:49 AM   #25
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by raconteur View Post
Please type "mount" (no quotes and no arguments) on a command line and post the results. That will tell us both whether the /var file system is mounted read-only, and if it is, what the arguments to mount (or fstab) should be to mount it read-write.

As an aside, what distribution are you running?
Thanks again for the help and for taking a look at this.

Yes, I believe I have Arch Linux from the uname -a: Linux 001cc040e18b 2.6.26-ARCH....

mount =

proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
/newroot/dev/hda1 on / type ext3 (rw,noatime)
none on /tmp type tmpfs (rw)
none on /newroot/var/log type tmpfs (rw)
none on /newroot/var/spool/cups type tmpfs (rw)
none on /usr/share/X11/xkb/compiled type tmpfs (rw)
none on /newroot/var/run type tmpfs (rw)
none on /newroot/var/tmp type tmpfs (rw)
none on /newroot/var/lib/dhcpcd type tmpfs (rw)
none on /root type tmpfs (rw)
none on /newroot/opt/wine-root/drive_c/windows/temp type tmpfs (rw)


So do I need to add something about /var/spool/cron in my fstab?

Last edited by grande25; 10-30-2008 at 11:07 AM.
 
Old 10-30-2008, 12:25 PM   #26
raconteur
Member
 
Registered: Dec 2007
Location: Slightly left of center
Distribution: slackware
Posts: 276
Blog Entries: 2

Rep: Reputation: 44
Sorry, I didn't notice the uname, I should have.
Though I'm not familiar with that distribution, it shouldn't matter, but if someone else here has more experience with it they may be able to help more than I.

I would try adding this to your fstab:
Code:
none /var/spool/cron tmpfs defaults 0 0
then type "mount -a", and check for errors, then type "mount" with no arguments to check that the directory was added to the tmpfs file system read-write.
 
Old 10-30-2008, 03:54 PM   #27
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Original Poster
Rep: Reputation: 15
That worked... Almost there I think. I can edit and save using crontab -e. But now the problem is it seems to be in a temporary status? My crontab resets when I reboot? is that because of the "tmpfs" in the fstab?

After I enter crontab -e it automatically calls the file /tmp/crontab.5DXsiN. I modify the crontab as */1 * * * * /filename. It asks me if I want to "save modified buffer". I tell it Yes to save modified buffer. Then it asks for file name to write. Default is /tmp/crontab.5DXsiN. I have saved with the default /tmp/crontab.5DXsiN and alternatively as /var/spool/cron/crontab.5DXsiN. It seems like the cron does execute my script because when I type crond at root it runs the edited cron and the script works. but after reboot the edited cron seems to be washed away.

Thanks again for the help Think this is almost done...

Last edited by grande25; 10-30-2008 at 04:04 PM.
 
Old 10-30-2008, 04:20 PM   #28
raconteur
Member
 
Registered: Dec 2007
Location: Slightly left of center
Distribution: slackware
Posts: 276
Blog Entries: 2

Rep: Reputation: 44
There are still some fundamental things we need to fix...

tmpfs is a volatile file system, data on it will probably be lost on reboot.
So we need to either mount /var/spool/cron on a partition on a physical volume, or as jlinkels suggested above, use /etc/crontab if your distribution includes it.
If you choose that method (/etc/crontab), there shouldn't be any need to explicitly mount the /var/spool/cron directory, you should be able to delete the fstab entry, but test that to be sure.

The random file extension in /tmp won't do you any good, don't bother saving those to /var/spool/cron... those are intermediate files used by the editor.
If your editor allows it, write to /var/spool/cron/crontabs/root (or whatever user name is pertinent).

hth
 
Old 10-30-2008, 04:46 PM   #29
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Original Poster
Rep: Reputation: 15
I don't have a /etc/crontab. there is a /etc/cron.daily and saving cron files there doesn't seem to do anything.
 
Old 10-30-2008, 04:53 PM   #30
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Original Poster
Rep: Reputation: 15
I guess I'll try to make a partition and mount it...
 
  


Reply

Tags
cron, help


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
about cron job yadava Linux - Newbie 2 08-25-2008 01:07 AM
at vs cron job mokku Solaris / OpenSolaris 2 05-16-2008 08:48 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
cron job thesnaggle Linux - Newbie 1 09-19-2003 11:47 AM
Cron job T-Rex Linux - Newbie 1 09-26-2001 12:28 PM


All times are GMT -5. The time now is 02:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration