Solved

executing a command using "at"

Posted on 2004-05-01
1
221 Views
Last Modified: 2010-05-18
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
Comment
Question by:ulto
1 Comment
 
LVL 4

Accepted Solution

by:
NVRAM earned 200 total points
ID: 10971460
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now