1

I'm looking for a way (bash script or other) to make a command run every minute using date - I've been looking around for similar solutions but they all suggest either cron or watch but what I want to do is to execute the command according to the output of date so that I could make the command run when the second hand hits 30, example 12:50:30 12:51:30 12:52:30 12:53:30 ... any help will be highly appreciated.

2
#!/bin/bash
until [[ $(date +%S) -eq 30 ]]
do
  sleep 0.75
done

while true
do
  #command & 
  #here your cmds should be forked to background to avoid delaying
  date +%S
  sleep 30
done

edit

as you wanted to see date +%S stdout and check if = 30 and execute somthing!

#!/bin/bash
foo(){
  echo yay
  #add commands here
}
while true
do
  date +%S | grep '30' && foo 
  sleep 1
done

or

#!/bin/bash
foo(){
  echo yay
  #add commands here
}
while true
do
  date +%S
  [[ $(date +%S) -eq 30 ]] && foo 
  sleep 1
done
4
  • Any idea what causes this? "trigger.sh: line 2: [[: 08: value too great for base (error token is "08")" Also I want the command to be triggered according to 'date' not to 'sleep 30' Nov 2 '15 at 19:25
  • Basically I want 'date +%S' to be executed every second and when the output is "30" the main command gets executed and so on. Nov 2 '15 at 19:31
  • Simply brilliant and clean - does exactly what's intended. Nov 4 '15 at 13:53
  • i'm glad that it works!
    – Yunus
    Nov 4 '15 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.