Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

executing a command using "at"

ok i have the follwoing two lines below that are executed from a php script on my webserver

this line matches the ip address with the mac address of a users and enters this information in to the ip tables

echo exec("sudo arp | grep $REMOTE_ADDR | awk '{print $1}'| /root/user/www/cgi-bin/change");

this one does the opposite EXCEPT there is a time delay of 24 hours (i want the script to execute then)

echo exec(" sudo arp | grep $REMOTE_ADDR | awk '{print $1}'| /root/user/www/cgi-bin/rem | at now + 24 hours ");

this is the one im having trouble with it works without the "sudo at now + 24 hours" but i need it to work with a time delay

it seems ok that there is a job waiting when i type atq to see the jobs in the queue but they dont execute at all properly
must be the order in which it appears or something
any ideas?
would cron do the trick!

also when i do the above i get a message sent to my /var/spool/mail/root
i get 2 errors saying
sh: line 26: Content-type:: command not found
sh: line 28: Content-type:: command not found

i dont understand this as when i run these scripts from the command line its fine and works with out fault (although there is one command not found error but the scripts works the way i want!?)

i need this urgent!

0
ulto
Asked:
ulto
1 Solution
 
NVRAMCommented:
Remember that 'at' reads *commands* from the stdin; it literally builds a shell script to reinstate your environment, cwd, etc. and then runs the commands that it had read.  The following will run the /root/user/www/cgi-bin/rem script *now* and send the output of that script (which apparently is HTML w/headers, and not a set of commands) to 'at':

>>echo exec(" sudo arp | grep $REMOTE_ADDR | awk '{print $1}'| /root/user/www/cgi-bin/rem | at now + 24 hours ");

I'm not conversant in PHP, but the shell command you wish to run is something like this, which runs arp+awk (simplified from grep+awk) *now* and the 'rem' script later:

   echo "echo `arp |  awk '/$REMOTE_ADDR/{print $1}'` | /root/user/www/cgi-bin/rem" | at now + 24 hours

so presumably, you'll want this in PHP:

   echo ("echo \"echo `arp |  awk '/$REMOTE_ADDR/{print $1}'` | /root/user/www/cgi-bin/rem\" | at now + 24 hours" );

Then you should end up with the HTML output of 'rem' in your mailbox.  (I took out the 'sudo' from before 'arp' since it doesn't seem necessary; YMMV)

Good luck.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now