How to run a shell command without shell access: use a cron job!
First published on February 23, 2007
There are times when installing a web application that you will need to run some shell commands. (OK, so there are many other times, but this is the most frequent scenario for me.) For example, you might have to set some permissions that are more complicated by the 755 and 400 stuff that can be done via FTP. You know, crazy code like this:
chmod a+rwx /home /home/mysite /home/mysite/tmp
(Stop snickering, you coding savvy ones!)
What to do if you haven’t been given shell access by your host?
Well, you could try to bug your host to give you shell access or send them whatever commands you need run. But a quicker solution might be to simply set up a cron job to run… right away. If you have cPanel, this is probably a built-in feature.
If you have a command where it wouldn’t hurt if it was run several times, just set it to run every minute, then wait a few minutes before deleting the cron job.
Poof, shell command executed!
Wondering what in the world a cron job is? Is just a scheduled server task. Usually I use this it to execute a php script at a certain time or at certain time intervals. Read about cron jobs or maybe even read my post about how I discovered the wonders of cron jobs to run backups of small databases.