I need a Bash Script for Debian which downloads a file, that file containts 1 or 0, 1 when the services is running, 0 when not. So how can I check if the file contains 1 or 0?
Asked
Active
Viewed 89 times
-5
-
2Downloads how? By HTTP? FTP? STFP? The "wget" tag implies HTTP, but would be good to be explicit. – JohnCC Aug 04 '14 at 09:52
-
wget http://yoursite.com/status.php – Ne00n Aug 04 '14 at 10:02
-
We generally don't write scripts for people - we prefer them to have a go themselves and then show their working when asking for help debugging. – user9517 Aug 04 '14 at 11:54
-
1Why do you need this? Why 0 and 1, why not 200 status. Why not a monitoring solution? What problem are you trying to solve? – Drew Khoury Aug 04 '14 at 12:22
2 Answers
1
Something like:-
status="$(curl -s http://yoursite.com/status.php)"
if [[ $status =~ ^1 ]]; then
# site is up...
fi

JohnCC
- 292
- 1
- 6
- 14
-
Dosent works i get line 3: =1: command not found, line 3 is if [[ in my script – Ne00n Aug 04 '14 at 11:45
-
1
Bourne shell generically has a nice way to evaluate the contents of a string (not using test or [[ or whatever).
contents=$(curl -s http://path/to/thing/with/zero_or_one)
case "$contents"
in
'1') echo "it was one"
;;
'2') echo "it was two"
;;
*) echo "it was something else
;;
esac

chris
- 11,944
- 6
- 42
- 51