Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

sudo and at commands

  • 27-04-2004 6:36pm
    #1
    Banned (with Prison Access) Posts: 13,018 ✭✭✭✭


    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 at now + 24 hours | sudo arp | grep $REMOTE_ADDR | awk '{print $1}'| /root/user/www/cgi-bin/rem");

    this is the one im having trouble with it works without the "sudo at now + 24 hours" but as that it just executes the command immediately!


Comments

  • Banned (with Prison Access) Posts: 13,018 ✭✭✭✭jank


    ok now i changed the order of the two lines and it seems to be working better but not fully
    the at command is working because when i do atq (find the queue of jobs) then it will show me whats wating
    but then the scripts themselves dont work it seems :(


  • Closed Accounts Posts: 294 ✭✭eggshapedfred


    i've never got the at command to work. i think it sux. you could try using the sleep command - sleep 24h. but you really don't want to do that. really.

    sorry i'm of no help


  • Registered Users, Registered Users 2 Posts: 1,186 ✭✭✭davej


    Often when you are using a job scheduler such as at, batch or the crontab the commands are run from a default shell with minimal PATH settings. Try specifying the full path to all of your commands.

    davej


  • Registered Users, Registered Users 2 Posts: 1,419 ✭✭✭nadir


    would cron not be jsut as handy? or is it not specific enough for this operation?


  • Registered Users, Registered Users 2 Posts: 1,862 ✭✭✭flamegrill


    Jank, this is a duplicate post.

    You've already been told more than once that it won't work. You can not call sudo from within a cron script its just stupid.

    use an infinite while loop started by root and use "sleep 5" within the loop to get it to check every 5 seconds and use full paths to local binaries, e.g. /usr/sbin/sudo as apposed to just sudo.

    Paul


  • Advertisement
  • Banned (with Prison Access) Posts: 13,018 ✭✭✭✭jank


    sorry about that but it was a different problem i had

    i dont get where your coming with the while loop
    all i want is to execute a command line with a time delay
    the command itself is fine but coupled with the "at" it just doesnt work

    u say i cant callled a cron script from sudo but im not using cron at all (is at a sub command of cron?) or maybe i am without knowing it!

    im new a linux so please bear with me
    if this will work any other way im open to suggestions,as im finding the "at" command very tempermental to say the least!!


  • Registered Users, Registered Users 2 Posts: 1,419 ✭✭✭nadir


    he means like this

    x=0; while [ $x -gt 0 ]; sleep 5; do echo $x; x=`echo "$x + 1" |bc`; done


  • Banned (with Prison Access) Posts: 13,018 ✭✭✭✭jank


    will i got it working eventually without the sudo command
    i more or less emdded the command i wanted in a another echo
    works perfectly now!!

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


Advertisement