You are not logged in.
Hello guys,
I am writing a small script which has to do the following:
1. It should run without any interruption. (Therefore while [ 1 ])
2. While working continuously, it should check whether a folder named "check" is available in the folder "/home/arch".
3. If it is the case, it should execute the script /home/arch/shutdownServer1
The bash script I am trying to execute is the following:
#!/bin/bash
while [ 1 ]
do
if [$(ls /home/arch | grep check)="check"]; then
/home/arch/shutdownServer1
fi
done
I tried to execute the code while the folder named "check" was available in the folder "/home/arch" But I got the following error.
/home/arch/myscript: line 5: [check=check]: command not found => This implies that the expression "$(ls /home/arch | grep check)" was evaluated correctly because of check=check. But why does it say "command not found"? Since check=check it should be evaluated as true and execute the script shutdownServer1?
P.S.: myscript is the name of the bash script file.
Guys, please help me.
Thanks in advance
Last edited by Archie_Enthusiasm (2010-11-29 12:20:58)
Offline
if [ -d /home/arch/check ]; then
Offline
Try one of these
if [ $(ls ~/ | grep check) ]; then
~/shutdownServer1
fi
or
[ $(ls ~/ | grep check) ] && ~/shutdownServer1
Edit: @Allan: thanks for '-d', I completely forgot that
Last edited by igndenok (2010-11-29 11:59:16)
Ask, and it shall be given you.
Seek, and ye shall find.
Knock, and it shall be opened unto you.
Offline
Not that using the grep like that, any file with "check" anywhere in its name will set off the script...
Offline
I would suggest to have a look at incrond [1] , what does exactly what you need.
Offline
THanks guys, arch linux community is the best community in the world! true story :-)
Offline