?
Solved

executing a command using "at"

Posted on 2004-05-01
1
Medium Priority
?
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
NVRAM earned 800 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

719 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