I have written the following line as a bash:
nmcli nm status id "My VPN id"> /home/Desktop/1.txt
So I want to check the id status and save it in the 1.txt
file.
Now I want to search in 1.txt
file and if it finds the word "connected"
then do nothing and if it does not find it run the following line:
nmcli con up id "My VPN id"
How can I write the search part?
Edit:
I made a bash script on a document on Desktop (with a name "s.sh"
as follows:
#!/bin/sh
nmcli nm status id 1> /home/Desktop/1.txt
grep -q connected /home/Desktop/1.txt || nmcli con up id 1
and edit the crontab as follows:
Saved the file. But the cron does not work!
grep "connected" 1.txt
. 0/1 whether pattern is present or not.