You are not logged in.

#1 2010-11-29 11:47:54

Archie_Enthusiasm
Member
Registered: 2010-10-23
Posts: 99

Can you please have a look on this small script?[SOLVED]

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

#2 2010-11-29 11:53:23

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,384
Website

Re: Can you please have a look on this small script?[SOLVED]

if [ -d /home/arch/check ]; then

Offline

#3 2010-11-29 11:57:42

igndenok
Member
From: Sidoarjo, Indonesia
Registered: 2010-06-07
Posts: 160

Re: Can you please have a look on this small script?[SOLVED]

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 tongue

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

#4 2010-11-29 11:59:18

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,384
Website

Re: Can you please have a look on this small script?[SOLVED]

Not that using the grep like that, any file with "check" anywhere in its name will set off the script...

Offline

#5 2010-11-29 12:18:11

dermarlo
Member
From: Wuppertal
Registered: 2010-09-19
Posts: 6
Website

Re: Can you please have a look on this small script?[SOLVED]

I would suggest to have a look at incrond [1] , what does exactly what you need.

[1] http://inotify.aiken.cz/?section=common … ws&lang=en

Offline

#6 2010-11-29 12:21:26

Archie_Enthusiasm
Member
Registered: 2010-10-23
Posts: 99

Re: Can you please have a look on this small script?[SOLVED]

THanks guys, arch linux community is the best community in the world! true story :-)

Offline

Board footer

Powered by FluxBB