Shell Scripting - return to previous loop until process is completed then die/done
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
I am writing a bash/shell script to automate some file filtering functions. Here is what I have written so far. Its based of a script I found online.
if (( $(ps -ef | grep $service | wc -l) > 0 ))
then
echo "$service is not done" >> /root/test.txt
else
(( $(wc -l /root/filter/first.txt) > 0 ))
if (( $(ps -ef | grep $service | wc -l) < 0 ))
then
./root/filter/filefilter.sh
else (( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
if (( $(ps -ef | grep awk | wc -l) > 0 ))
then
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
else
# here is where I would like it to loop until the filtering is complete
# then once the final file is > 0 stop/die/done
fi
fi
fi
I would like it loop until the final.txt has been created in the dir, I will add that part in, just need assistance on the loop or return function ( if return can be used to return to line 1 and start running the script again until the final.txt is created then die/done/stop)
linux bash shell-script
migrated from serverfault.com May 17 '15 at 20:43
This question came from our site for system and network administrators.
|
show 3 more comments
up vote
-1
down vote
favorite
I am writing a bash/shell script to automate some file filtering functions. Here is what I have written so far. Its based of a script I found online.
if (( $(ps -ef | grep $service | wc -l) > 0 ))
then
echo "$service is not done" >> /root/test.txt
else
(( $(wc -l /root/filter/first.txt) > 0 ))
if (( $(ps -ef | grep $service | wc -l) < 0 ))
then
./root/filter/filefilter.sh
else (( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
if (( $(ps -ef | grep awk | wc -l) > 0 ))
then
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
else
# here is where I would like it to loop until the filtering is complete
# then once the final file is > 0 stop/die/done
fi
fi
fi
I would like it loop until the final.txt has been created in the dir, I will add that part in, just need assistance on the loop or return function ( if return can be used to return to line 1 and start running the script again until the final.txt is created then die/done/stop)
linux bash shell-script
migrated from serverfault.com May 17 '15 at 20:43
This question came from our site for system and network administrators.
Take a look at shellcheck.net and please indent your code.
– Cyrus
May 17 '15 at 6:00
As I mentioned I am new to coding and I do not know what you mean by indent, I followed the serverfault rules and made the code show up in the code box.
– LinSheller
May 17 '15 at 6:06
I do not need the code checked as the site you posted does, I need help coding it to loop back to line 1 until the final.txt is not empty then die/done/stop so unfortunately your link does not help me.
– LinSheller
May 17 '15 at 6:08
2
Also, what you're looking for iswhile
instead ofif
on the first line. The man page for bash should tell you how it works.
– Jenny D
May 17 '15 at 6:13
2
you should probably be using[ -s
filename
]
for most of thosewc -l
tests,
– mikeserv
May 18 '15 at 1:35
|
show 3 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I am writing a bash/shell script to automate some file filtering functions. Here is what I have written so far. Its based of a script I found online.
if (( $(ps -ef | grep $service | wc -l) > 0 ))
then
echo "$service is not done" >> /root/test.txt
else
(( $(wc -l /root/filter/first.txt) > 0 ))
if (( $(ps -ef | grep $service | wc -l) < 0 ))
then
./root/filter/filefilter.sh
else (( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
if (( $(ps -ef | grep awk | wc -l) > 0 ))
then
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
else
# here is where I would like it to loop until the filtering is complete
# then once the final file is > 0 stop/die/done
fi
fi
fi
I would like it loop until the final.txt has been created in the dir, I will add that part in, just need assistance on the loop or return function ( if return can be used to return to line 1 and start running the script again until the final.txt is created then die/done/stop)
linux bash shell-script
I am writing a bash/shell script to automate some file filtering functions. Here is what I have written so far. Its based of a script I found online.
if (( $(ps -ef | grep $service | wc -l) > 0 ))
then
echo "$service is not done" >> /root/test.txt
else
(( $(wc -l /root/filter/first.txt) > 0 ))
if (( $(ps -ef | grep $service | wc -l) < 0 ))
then
./root/filter/filefilter.sh
else (( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
if (( $(ps -ef | grep awk | wc -l) > 0 ))
then
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
else
# here is where I would like it to loop until the filtering is complete
# then once the final file is > 0 stop/die/done
fi
fi
fi
I would like it loop until the final.txt has been created in the dir, I will add that part in, just need assistance on the loop or return function ( if return can be used to return to line 1 and start running the script again until the final.txt is created then die/done/stop)
linux bash shell-script
linux bash shell-script
edited 2 days ago
Rui F Ribeiro
38.2k1475123
38.2k1475123
asked May 17 '15 at 5:33
LinSheller
migrated from serverfault.com May 17 '15 at 20:43
This question came from our site for system and network administrators.
migrated from serverfault.com May 17 '15 at 20:43
This question came from our site for system and network administrators.
Take a look at shellcheck.net and please indent your code.
– Cyrus
May 17 '15 at 6:00
As I mentioned I am new to coding and I do not know what you mean by indent, I followed the serverfault rules and made the code show up in the code box.
– LinSheller
May 17 '15 at 6:06
I do not need the code checked as the site you posted does, I need help coding it to loop back to line 1 until the final.txt is not empty then die/done/stop so unfortunately your link does not help me.
– LinSheller
May 17 '15 at 6:08
2
Also, what you're looking for iswhile
instead ofif
on the first line. The man page for bash should tell you how it works.
– Jenny D
May 17 '15 at 6:13
2
you should probably be using[ -s
filename
]
for most of thosewc -l
tests,
– mikeserv
May 18 '15 at 1:35
|
show 3 more comments
Take a look at shellcheck.net and please indent your code.
– Cyrus
May 17 '15 at 6:00
As I mentioned I am new to coding and I do not know what you mean by indent, I followed the serverfault rules and made the code show up in the code box.
– LinSheller
May 17 '15 at 6:06
I do not need the code checked as the site you posted does, I need help coding it to loop back to line 1 until the final.txt is not empty then die/done/stop so unfortunately your link does not help me.
– LinSheller
May 17 '15 at 6:08
2
Also, what you're looking for iswhile
instead ofif
on the first line. The man page for bash should tell you how it works.
– Jenny D
May 17 '15 at 6:13
2
you should probably be using[ -s
filename
]
for most of thosewc -l
tests,
– mikeserv
May 18 '15 at 1:35
Take a look at shellcheck.net and please indent your code.
– Cyrus
May 17 '15 at 6:00
Take a look at shellcheck.net and please indent your code.
– Cyrus
May 17 '15 at 6:00
As I mentioned I am new to coding and I do not know what you mean by indent, I followed the serverfault rules and made the code show up in the code box.
– LinSheller
May 17 '15 at 6:06
As I mentioned I am new to coding and I do not know what you mean by indent, I followed the serverfault rules and made the code show up in the code box.
– LinSheller
May 17 '15 at 6:06
I do not need the code checked as the site you posted does, I need help coding it to loop back to line 1 until the final.txt is not empty then die/done/stop so unfortunately your link does not help me.
– LinSheller
May 17 '15 at 6:08
I do not need the code checked as the site you posted does, I need help coding it to loop back to line 1 until the final.txt is not empty then die/done/stop so unfortunately your link does not help me.
– LinSheller
May 17 '15 at 6:08
2
2
Also, what you're looking for is
while
instead of if
on the first line. The man page for bash should tell you how it works.– Jenny D
May 17 '15 at 6:13
Also, what you're looking for is
while
instead of if
on the first line. The man page for bash should tell you how it works.– Jenny D
May 17 '15 at 6:13
2
2
you should probably be using
[ -s
filename
]
for most of those wc -l
tests,– mikeserv
May 18 '15 at 1:35
you should probably be using
[ -s
filename
]
for most of those wc -l
tests,– mikeserv
May 18 '15 at 1:35
|
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
I don't really understand some parts of your code.
1) Does the script filefilter.sh performs the filtering?
2) If yes, in what condition will it filters (eg. $service exist)
3) Are you filtering selected services or all processes running
Indent is pretty important in scripting as you can easily spot the loops clearly
[ Your Code ]:
if (( $(ps -ef | grep $service | wc -l) > 0 ))
then
echo "$service is not done" >> /root/test.txt
else
(( $(wc -l /root/filter/first.txt) > 0 )) #There is no condition required for the else-loop
if (( $(ps -ef | grep $service | wc -l) < 0 ))
then
./root/filter/filefilter.sh
else
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 )) #There is no condition required for the else-loop
if (( $(ps -ef | grep awk | wc -l) > 0 ))
then
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
else
#You can use the exit command to stop the loop base on the condition you want
fi
fi
fi
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I don't really understand some parts of your code.
1) Does the script filefilter.sh performs the filtering?
2) If yes, in what condition will it filters (eg. $service exist)
3) Are you filtering selected services or all processes running
Indent is pretty important in scripting as you can easily spot the loops clearly
[ Your Code ]:
if (( $(ps -ef | grep $service | wc -l) > 0 ))
then
echo "$service is not done" >> /root/test.txt
else
(( $(wc -l /root/filter/first.txt) > 0 )) #There is no condition required for the else-loop
if (( $(ps -ef | grep $service | wc -l) < 0 ))
then
./root/filter/filefilter.sh
else
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 )) #There is no condition required for the else-loop
if (( $(ps -ef | grep awk | wc -l) > 0 ))
then
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
else
#You can use the exit command to stop the loop base on the condition you want
fi
fi
fi
add a comment |
up vote
0
down vote
I don't really understand some parts of your code.
1) Does the script filefilter.sh performs the filtering?
2) If yes, in what condition will it filters (eg. $service exist)
3) Are you filtering selected services or all processes running
Indent is pretty important in scripting as you can easily spot the loops clearly
[ Your Code ]:
if (( $(ps -ef | grep $service | wc -l) > 0 ))
then
echo "$service is not done" >> /root/test.txt
else
(( $(wc -l /root/filter/first.txt) > 0 )) #There is no condition required for the else-loop
if (( $(ps -ef | grep $service | wc -l) < 0 ))
then
./root/filter/filefilter.sh
else
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 )) #There is no condition required for the else-loop
if (( $(ps -ef | grep awk | wc -l) > 0 ))
then
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
else
#You can use the exit command to stop the loop base on the condition you want
fi
fi
fi
add a comment |
up vote
0
down vote
up vote
0
down vote
I don't really understand some parts of your code.
1) Does the script filefilter.sh performs the filtering?
2) If yes, in what condition will it filters (eg. $service exist)
3) Are you filtering selected services or all processes running
Indent is pretty important in scripting as you can easily spot the loops clearly
[ Your Code ]:
if (( $(ps -ef | grep $service | wc -l) > 0 ))
then
echo "$service is not done" >> /root/test.txt
else
(( $(wc -l /root/filter/first.txt) > 0 )) #There is no condition required for the else-loop
if (( $(ps -ef | grep $service | wc -l) < 0 ))
then
./root/filter/filefilter.sh
else
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 )) #There is no condition required for the else-loop
if (( $(ps -ef | grep awk | wc -l) > 0 ))
then
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
else
#You can use the exit command to stop the loop base on the condition you want
fi
fi
fi
I don't really understand some parts of your code.
1) Does the script filefilter.sh performs the filtering?
2) If yes, in what condition will it filters (eg. $service exist)
3) Are you filtering selected services or all processes running
Indent is pretty important in scripting as you can easily spot the loops clearly
[ Your Code ]:
if (( $(ps -ef | grep $service | wc -l) > 0 ))
then
echo "$service is not done" >> /root/test.txt
else
(( $(wc -l /root/filter/first.txt) > 0 )) #There is no condition required for the else-loop
if (( $(ps -ef | grep $service | wc -l) < 0 ))
then
./root/filter/filefilter.sh
else
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 )) #There is no condition required for the else-loop
if (( $(ps -ef | grep awk | wc -l) > 0 ))
then
(( $(ls | grep /root/filter/final.txt | wc -l) > 0 ))
else
#You can use the exit command to stop the loop base on the condition you want
fi
fi
fi
answered Jun 3 '15 at 8:08
Win.T
4721612
4721612
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f203966%2fshell-scripting-return-to-previous-loop-until-process-is-completed-then-die-do%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Take a look at shellcheck.net and please indent your code.
– Cyrus
May 17 '15 at 6:00
As I mentioned I am new to coding and I do not know what you mean by indent, I followed the serverfault rules and made the code show up in the code box.
– LinSheller
May 17 '15 at 6:06
I do not need the code checked as the site you posted does, I need help coding it to loop back to line 1 until the final.txt is not empty then die/done/stop so unfortunately your link does not help me.
– LinSheller
May 17 '15 at 6:08
2
Also, what you're looking for is
while
instead ofif
on the first line. The man page for bash should tell you how it works.– Jenny D
May 17 '15 at 6:13
2
you should probably be using
[ -s
filename
]
for most of thosewc -l
tests,– mikeserv
May 18 '15 at 1:35