LinuxQuestions.org
Help answer threads with 0 replies.
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-25-2008, 06:39 PM   #1
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Rep: Reputation: 15
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
 
Old 10-25-2008, 07:12 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,311

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
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.
 
Old 10-25-2008, 10:53 PM   #3
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,192

Rep: Reputation: 538Reputation: 538Reputation: 538Reputation: 538Reputation: 538Reputation: 538
You can set the editor of choice with the VISUAL environment variable if you are not feeling comfortable with vi.

Code:
export VISUAL=nano
jlinkels
 
Old 10-26-2008, 09:48 AM   #4
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Original Poster
Rep: Reputation: 15
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
 
Old 10-26-2008, 10:13 AM   #5
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 59
Quote:
Originally Posted by grande25 View Post
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?
Being root has nothing to do with where you are in the directory tree. It has to do with how you log into your system. If you log in as username root and then the root password, you're root. If you log in with a regular user name and then that user's password, you're a regular user. (There are wrinkles later, because the root user can use su to become other users, and some regular users can su to become root, but that's not important right this second.)

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.

Last edited by Telemachos; 10-26-2008 at 10:40 AM.
 
Old 10-26-2008, 03:36 PM   #6
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Telemachos View Post
Being root has nothing to do with where you are in the directory tree. It has to do with how you log into your system. If you log in as username root and then the root password, you're root. If you log in with a regular user name and then that user's password, you're a regular user. (There are wrinkles later, because the root user can use su to become other users, and some regular users can su to become root, but that's not important right this second.)

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.

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#

Last edited by grande25; 10-26-2008 at 04:50 PM.
 
Old 10-26-2008, 04:55 PM   #7
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jlinkels View Post
You can set the editor of choice with the VISUAL environment variable if you are not feeling comfortable with vi.

Code:
export VISUAL=nano
jlinkels

Thanks for that.
 
Old 10-26-2008, 06:46 PM   #8
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,311

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
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

mail

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
 
Old 10-26-2008, 07:40 PM   #9
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Original Poster
Rep: Reputation: 15
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

Last edited by grande25; 10-26-2008 at 07:41 PM.
 
Old 10-26-2008, 09:03 PM   #10
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 59
Quote:
Originally Posted by grande25 View Post
sh-3.2# is at command prompt so I assume that is the version?
Nope, the number you see there is the version of your shell (probably Bash). This command might tell you more about your operating system:
Code:
uname -a
Quote:
Originally Posted by grande
It's a webpage. What did you try to open it with?
 
Old 10-27-2008, 03:40 PM   #11
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Original Poster
Rep: Reputation: 15
uname -a = Linux 001cc040e18b 2.6.26-ARCH #1 SMP PREEMPT...

So anyone have some actual help with this?
 
Old 10-27-2008, 04:09 PM   #12
raconteur
Member
 
Registered: Dec 2007
Location: Slightly left of center
Distribution: slackware
Posts: 276
Blog Entries: 2

Rep: Reputation: 44
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?
 
Old 10-27-2008, 04:13 PM   #13
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 59
Quote:
Originally Posted by grande25 View Post
uname -a = Linux 001cc040e18b 2.6.26-ARCH #1 SMP PREEMPT...

So anyone have some actual help with this?
It's hard to help since we are guessing at a fairly unusual situation. Normally, the root user should be able to edit whatever files he or she wants. As Chris suggested, the problem may be that your drive is mounted read-only. You still haven't posted the output of cat /etc/fstab which would help.

(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?)

Last edited by Telemachos; 10-27-2008 at 04:15 PM.
 
Old 10-27-2008, 04:50 PM   #14
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Original Poster
Rep: Reputation: 15
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?

Last edited by grande25; 10-27-2008 at 05:58 PM.
 
Old 10-27-2008, 05:21 PM   #15
grande25
LQ Newbie
 
Registered: Oct 2008
Posts: 29

Original Poster
Rep: Reputation: 15
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

Last edited by grande25; 10-27-2008 at 07:17 PM.
 
  


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 01:04 PM.

Main Menu
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