LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-23-2003, 07:18 AM   #1
tazio
LQ Newbie
 
Registered: Oct 2003
Posts: 5

Rep: Reputation: 0
adding a job to crontab via shell script


hi all,
im not that what someone calls a shell guru , not to say i suck at shell scripting
but i m in need of some info about the following:

is it possible to add a job to crontab with a shell script?
i want to have a user configure some things through a webfrontend, php generates some required files and finally a shell script, triggered by php, adds a new line to crontab.
is this black magic or is it that im lame?

any help is welcome, thanks

tazio
 
Old 10-23-2003, 08:12 AM   #2
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
I guess you could, but it's an ugly way to use cron IMHO.

Just append the line you want to add to /var/spool/cron/crontabs/$USER. The location of the users' crontabs may be different on your distro (I run Debian).

You would need to make sure the user Apache runs as has write access to the crontab(s) you wish to alter, but keep in mind this is *extremely* bad security-wise. Someone could add whatever commands they want to your crontab if you're not extremely cautious and know exactly what you're doing.

Håkan
 
Old 10-23-2003, 08:14 AM   #3
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
from the manual I see some interesting options:

Quote:
crontab file [-u user] - replace crontab from file

crontab - [-u user] - replace crontab from stdin

crontab -l [user] - list crontab for user
If you run crontab -l, the contents of the crontab is returned. After adding a line, and return it to "crontab -", you've modified the crontab.

I haven't tested this, but these lines might work:

Code:
newline="the contents of the new crontab line"
(crontab -l; echo "$newline") | crontab -
this is not black magic some shell powers really make Linux feel like magic to me... and this is all reality

Last edited by yapp; 10-23-2003 at 08:15 AM.
 
Old 10-23-2003, 08:15 AM   #4
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
How would that work when Apache (which runs PHP, which in turns executes the shell script) doesn't run as the user who owns the crontab you wish to edit? Using expect and using su and the root password in the script wouldn't be good at all.

I'd rather add the Apache user to the crontab group, but I don't know what's worse security-wise.

Håkan

Last edited by hw-tph; 10-23-2003 at 08:18 AM.
 
Old 10-23-2003, 08:18 AM   #5
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
thanks. ...and I'm a little amazed; you've posted your reply in a few seconds, while I was editing my post


does anyone know btw how to start a script as a different user then 'httpd'? I'm still obsessed with running fetchmail from a PHP or CGI script.
 
Old 10-23-2003, 08:19 AM   #6
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
Now we're crossposting. I replied, reread your reply and then changed my post. And now I'll try to find out a better solution.

Håkan
 
Old 10-23-2003, 09:12 AM   #7
tazio
LQ Newbie
 
Registered: Oct 2003
Posts: 5

Original Poster
Rep: Reputation: 0
thanks for the quick answers!
yes im aware of the security aspects, its just the beginning of a project and i have to think about many many many things
this machine wouldnt be accessible from the net, just one or two persons have acces to this machine and the main reason is to edit some timetable of on or two cronjobs...
so they cant put theyre own commands into this file, only the time when a job should start should be edited.

so now i start trying to f*ck things up

thanks

tazio
 
Old 10-23-2003, 02:44 PM   #8
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
Quote:
Originally posted by hw-tph
Now we're crossposting. I replied, reread your reply and then changed my post. And now I'll try to find out a better solution.

Håkan
yup. that wasn't really smart we shouldn't edit our posts that much

But a solution I was looking for is something like 'suexec' (haven't tried that one though yet).. ie a program that changes to another user, and executes the command.

To switch to another user, you need to become root first. A suid-root program like 'su', or 'suexec' does this. If you call "su <otheruser>", it simply changes directly to another user environment
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
my database export shell script run from command line but not form crontab saifee Linux - General 11 01-29-2012 09:24 AM
Adding new users via Shell script coolfrog Linux - General 10 12-05-2010 10:47 AM
Shell script adding autostart gnome script Coolrunr Programming 3 01-01-2009 02:23 PM
shell script fo run auto job in cron JolynnMarie LinuxQuestions.org Member Intro 0 04-28-2004 11:21 AM
Shell script running via crontab problem. thetruethugg Linux - Software 13 12-19-2003 08:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:24 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
Open Source Consulting | Domain Registration