Solved

executing a command using "at"

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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need bundled ATFTP tool for use with ESXi 4 106
pipe to sed or perl, please help 5 145
updating the repos in yum 4 121
Help with Ubuntu 14.04 LTS 10 142
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 …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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