Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
13
rated 0 times [  13] [ 0]  / answers: 1 / hits: 2119  / 3 Years ago, sat, june 26, 2021, 2:43:17

I need to run repeatedly (every 3600 seconds) the following commands from the terminal:



if whois abcxyz.com | grep -q 'string'; then
echo 'Message line 1'
echo 'Message line 2'
fi


I tried using watch, as follows:



watch -n 3600 if whois abcxyz.com | grep -q 'string'; then
echo 'Message line 1'
echo 'Message line 2'
fi


but I get error messages.



Could you please help me make it work?



Thanks


More From » bash

 Answers
1

Since watch [options] command executes command using sh -c by default, you can use it run snippets of shell code directly provided that:




  1. you get the quoting right



and




  1. your code is sh-compatible i.e. doesn't use any bash/zsh/csh-"isms"



So for example



$ watch -n 36 'if whois abcxyz.com | grep -q "string"; then
echo "Message line 1" | ts
echo "Message line 2" | ts
fi'

[#3847] Sunday, June 27, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
olouredping

Total Points: 259
Total Questions: 100
Total Answers: 121

Location: New Caledonia
Member since Wed, Sep 15, 2021
3 Years ago
;