Linux - GeneralThis 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
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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.