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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
10-25-2008, 05:39 PM
|
#1
|
|
LQ Newbie
Registered: Oct 2008
Posts: 29
Rep:
|
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
|
|
|
|
10-25-2008, 06:12 PM
|
#2
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 15,261
|
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.
|
|
|
|
10-25-2008, 09:53 PM
|
#3
|
|
Senior Member
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 3,832
|
You can set the editor of choice with the VISUAL environment variable if you are not feeling comfortable with vi.
jlinkels
|
|
|
|
10-26-2008, 08:48 AM
|
#4
|
|
LQ Newbie
Registered: Oct 2008
Posts: 29
Original Poster
Rep:
|
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
|
|
|
|
10-26-2008, 09:13 AM
|
#5
|
|
Member
Registered: May 2007
Distribution: Debian
Posts: 754
Rep:
|
Quote:
Originally Posted by grande25
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 09:40 AM.
|
|
|
|
10-26-2008, 02:36 PM
|
#6
|
|
LQ Newbie
Registered: Oct 2008
Posts: 29
Original Poster
Rep:
|
Quote:
Originally Posted by Telemachos
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 03:50 PM.
|
|
|
|
10-26-2008, 03:55 PM
|
#7
|
|
LQ Newbie
Registered: Oct 2008
Posts: 29
Original Poster
Rep:
|
Quote:
Originally Posted by jlinkels
You can set the editor of choice with the VISUAL environment variable if you are not feeling comfortable with vi.
jlinkels
|
Thanks for that.
|
|
|
|
10-26-2008, 05:46 PM
|
#8
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 15,261
|
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
|
|
|
|
10-26-2008, 06:40 PM
|
#9
|
|
LQ Newbie
Registered: Oct 2008
Posts: 29
Original Poster
Rep:
|
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 06:41 PM.
|
|
|
|
10-26-2008, 08:03 PM
|
#10
|
|
Member
Registered: May 2007
Distribution: Debian
Posts: 754
Rep:
|
Quote:
Originally Posted by grande25
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:
Quote:
|
Originally Posted by grande
|
It's a webpage. What did you try to open it with?
|
|
|
|
10-27-2008, 02:40 PM
|
#11
|
|
LQ Newbie
Registered: Oct 2008
Posts: 29
Original Poster
Rep:
|
uname -a = Linux 001cc040e18b 2.6.26-ARCH #1 SMP PREEMPT...
So anyone have some actual help with this?
|
|
|
|
10-27-2008, 03:09 PM
|
#12
|
|
Member
Registered: Dec 2007
Location: Slightly left of center
Distribution: slackware
Posts: 276
Rep:
|
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?
|
|
|
|
10-27-2008, 03:13 PM
|
#13
|
|
Member
Registered: May 2007
Distribution: Debian
Posts: 754
Rep:
|
Quote:
Originally Posted by grande25
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 03:15 PM.
|
|
|
|
10-27-2008, 03:50 PM
|
#14
|
|
LQ Newbie
Registered: Oct 2008
Posts: 29
Original Poster
Rep:
|
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 04:58 PM.
|
|
|
|
10-27-2008, 04:21 PM
|
#15
|
|
LQ Newbie
Registered: Oct 2008
Posts: 29
Original Poster
Rep:
|
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 06:17 PM.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:59 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|