Solved

executing a command using "at"

Posted on 2004-05-01
1
222 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help Linux centos 5.7 3 87
script 11 137
CENTOS7 DL380 G5  failed to install even after hpsa allowed 5 1,010
Stopping flocksnippet: Killed (core dumped) on doing kill -9 5 70
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 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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

919 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

13 Experts available now in Live!

Get 1:1 Help Now