Run a command at a specific time

后端 未结 5 706
闹比i
闹比i 2021-01-31 04:36

I\'m trying to run a command at a specific time. I\'ve looked at the \"at\" command, but I don\'t know how to get it working...

Here\'s what I do:

at 184         


        
5条回答
  •  一生所求
    2021-01-31 05:17

    The at command is not installed by default to the systems I work (Ubuntu, RHEL) and I don't have permissions to install new software, so I use scripts that combine bash and awk in order to achieve the at functionality as follows:

    #! /bin/bash
    
    res=""
    while [ ! $res ]; do
    
        res=$( date | awk -v hour=$1 -v min=$2 '{ 
    
            split($4, tmp, ":" );
    
            if( (tmp[1] == hour) && (tmp[2] == min) )
            {
                print "ok";   
            }
            else
            {
                print "";
            }
    
        }' )
    
    done
    

    ./atReplacement.sh $HOUR $MIN; [OTHER_COMMANDS]

提交回复
热议问题