Bash Script not looping [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I've got a script that should keep execute a function when a file name changes - the issue i'm having is that after the first execution the while loop doesn't continue to run. The script doesn't exit it appears to just hang. Anyone any ideas?



#!/bin/bash
#*******
#10.0.4.****

set -x
#trap read debug

end=432000
state='unknown'

cachereset()
rm ~/state/*.txt
cp /media/state/*.txt ~/state/
echo "unknown"


statecheck()
if [ -f ~/state/meeting.txt ]; then
pkill google-chrome
google-chrome https://**** --incognito & #Load Chromium
sleep 30 #Wait for Chromium to load
xdotool type "****@****.co.uk"
xdotool key Tab
xdotool type "PASS!"
xdotool key Return
sleep 15
xdotool key F11
echo "meeting"
elif [ -f ~/state/normal.txt ]; then
pkill google-chrome
google-chrome https://**** --incognito & #Load Chromium
sleep 30 #Wait for Chromium to load
xdotool type "***@****.co.uk"
xdotool key Tab
xdotool type "PASS!"
xdotool key Return
sleep 15
xdotool key F11
echo "normal"
else
pkill google-chrome
google-chrome https://**** --incognito & #Load Chromium
sleep 30 #Wait for Chromium to load
xdotool type "***@*****.co.uk"
xdotool key Tab
xdotool type "PASS!"
xdotool key Return
sleep 15
xdotool key F11
echo "normal"
fi


state=$(cachereset)

while [ $SECONDS -lt $end ]; do
echo "frank"
if [ $state == "unknown" ]; then
state=$(statecheck)
fi
if [ $state == "meeting" ]; then
while [ -f /media/state/meeting.txt ]; do
sleep 30
done
state=$(cachereset)
fi
if [ $state == "normal" ]; then
while [ -f /media/state/normal.txt ]; do
sleep 30
done
state=$(cachereset)
fi
done

shutdown -r 1









share|improve this question















closed as unclear what you're asking by Jeff Schaller, RalfFriedl, Thomas, schily, Archemar Sep 8 at 13:23


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 1




    You may find inotifywait to be useful.
    – ctrl-alt-delor
    Sep 5 at 15:25






  • 2




    an appearance of hanging could result from either of your while [ -f /media/state/... sleep 30 loops, as long as either of those files exist, then bash will do infinite 30-second loops. Is that what your set -x output is indicating?
    – Jeff Schaller
    Sep 5 at 15:38






  • 1




    To execute a bash script in debug mode prepend the script by -x: bash -x yourscript that way you can see what the script is doing and where it enters a loop or blocks.
    – YoMismo
    Sep 6 at 6:47










  • @JeffSchaller the script is meant to loop indefinitely whilst the file is still present (well for 5 days while the main loop still runs) the issue is that looking at the debug output will run perfectly until after the first time state=$(statecheck) runs and then there's no further output. Changing the file that it monitors doesn't result in any changes either.
    – Dan
    Sep 7 at 15:20










  • What's the last line from set -x before it hangs?
    – Jeff Schaller
    Sep 7 at 19:57














up vote
1
down vote

favorite












I've got a script that should keep execute a function when a file name changes - the issue i'm having is that after the first execution the while loop doesn't continue to run. The script doesn't exit it appears to just hang. Anyone any ideas?



#!/bin/bash
#*******
#10.0.4.****

set -x
#trap read debug

end=432000
state='unknown'

cachereset()
rm ~/state/*.txt
cp /media/state/*.txt ~/state/
echo "unknown"


statecheck()
if [ -f ~/state/meeting.txt ]; then
pkill google-chrome
google-chrome https://**** --incognito & #Load Chromium
sleep 30 #Wait for Chromium to load
xdotool type "****@****.co.uk"
xdotool key Tab
xdotool type "PASS!"
xdotool key Return
sleep 15
xdotool key F11
echo "meeting"
elif [ -f ~/state/normal.txt ]; then
pkill google-chrome
google-chrome https://**** --incognito & #Load Chromium
sleep 30 #Wait for Chromium to load
xdotool type "***@****.co.uk"
xdotool key Tab
xdotool type "PASS!"
xdotool key Return
sleep 15
xdotool key F11
echo "normal"
else
pkill google-chrome
google-chrome https://**** --incognito & #Load Chromium
sleep 30 #Wait for Chromium to load
xdotool type "***@*****.co.uk"
xdotool key Tab
xdotool type "PASS!"
xdotool key Return
sleep 15
xdotool key F11
echo "normal"
fi


state=$(cachereset)

while [ $SECONDS -lt $end ]; do
echo "frank"
if [ $state == "unknown" ]; then
state=$(statecheck)
fi
if [ $state == "meeting" ]; then
while [ -f /media/state/meeting.txt ]; do
sleep 30
done
state=$(cachereset)
fi
if [ $state == "normal" ]; then
while [ -f /media/state/normal.txt ]; do
sleep 30
done
state=$(cachereset)
fi
done

shutdown -r 1









share|improve this question















closed as unclear what you're asking by Jeff Schaller, RalfFriedl, Thomas, schily, Archemar Sep 8 at 13:23


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 1




    You may find inotifywait to be useful.
    – ctrl-alt-delor
    Sep 5 at 15:25






  • 2




    an appearance of hanging could result from either of your while [ -f /media/state/... sleep 30 loops, as long as either of those files exist, then bash will do infinite 30-second loops. Is that what your set -x output is indicating?
    – Jeff Schaller
    Sep 5 at 15:38






  • 1




    To execute a bash script in debug mode prepend the script by -x: bash -x yourscript that way you can see what the script is doing and where it enters a loop or blocks.
    – YoMismo
    Sep 6 at 6:47










  • @JeffSchaller the script is meant to loop indefinitely whilst the file is still present (well for 5 days while the main loop still runs) the issue is that looking at the debug output will run perfectly until after the first time state=$(statecheck) runs and then there's no further output. Changing the file that it monitors doesn't result in any changes either.
    – Dan
    Sep 7 at 15:20










  • What's the last line from set -x before it hangs?
    – Jeff Schaller
    Sep 7 at 19:57












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I've got a script that should keep execute a function when a file name changes - the issue i'm having is that after the first execution the while loop doesn't continue to run. The script doesn't exit it appears to just hang. Anyone any ideas?



#!/bin/bash
#*******
#10.0.4.****

set -x
#trap read debug

end=432000
state='unknown'

cachereset()
rm ~/state/*.txt
cp /media/state/*.txt ~/state/
echo "unknown"


statecheck()
if [ -f ~/state/meeting.txt ]; then
pkill google-chrome
google-chrome https://**** --incognito & #Load Chromium
sleep 30 #Wait for Chromium to load
xdotool type "****@****.co.uk"
xdotool key Tab
xdotool type "PASS!"
xdotool key Return
sleep 15
xdotool key F11
echo "meeting"
elif [ -f ~/state/normal.txt ]; then
pkill google-chrome
google-chrome https://**** --incognito & #Load Chromium
sleep 30 #Wait for Chromium to load
xdotool type "***@****.co.uk"
xdotool key Tab
xdotool type "PASS!"
xdotool key Return
sleep 15
xdotool key F11
echo "normal"
else
pkill google-chrome
google-chrome https://**** --incognito & #Load Chromium
sleep 30 #Wait for Chromium to load
xdotool type "***@*****.co.uk"
xdotool key Tab
xdotool type "PASS!"
xdotool key Return
sleep 15
xdotool key F11
echo "normal"
fi


state=$(cachereset)

while [ $SECONDS -lt $end ]; do
echo "frank"
if [ $state == "unknown" ]; then
state=$(statecheck)
fi
if [ $state == "meeting" ]; then
while [ -f /media/state/meeting.txt ]; do
sleep 30
done
state=$(cachereset)
fi
if [ $state == "normal" ]; then
while [ -f /media/state/normal.txt ]; do
sleep 30
done
state=$(cachereset)
fi
done

shutdown -r 1









share|improve this question















I've got a script that should keep execute a function when a file name changes - the issue i'm having is that after the first execution the while loop doesn't continue to run. The script doesn't exit it appears to just hang. Anyone any ideas?



#!/bin/bash
#*******
#10.0.4.****

set -x
#trap read debug

end=432000
state='unknown'

cachereset()
rm ~/state/*.txt
cp /media/state/*.txt ~/state/
echo "unknown"


statecheck()
if [ -f ~/state/meeting.txt ]; then
pkill google-chrome
google-chrome https://**** --incognito & #Load Chromium
sleep 30 #Wait for Chromium to load
xdotool type "****@****.co.uk"
xdotool key Tab
xdotool type "PASS!"
xdotool key Return
sleep 15
xdotool key F11
echo "meeting"
elif [ -f ~/state/normal.txt ]; then
pkill google-chrome
google-chrome https://**** --incognito & #Load Chromium
sleep 30 #Wait for Chromium to load
xdotool type "***@****.co.uk"
xdotool key Tab
xdotool type "PASS!"
xdotool key Return
sleep 15
xdotool key F11
echo "normal"
else
pkill google-chrome
google-chrome https://**** --incognito & #Load Chromium
sleep 30 #Wait for Chromium to load
xdotool type "***@*****.co.uk"
xdotool key Tab
xdotool type "PASS!"
xdotool key Return
sleep 15
xdotool key F11
echo "normal"
fi


state=$(cachereset)

while [ $SECONDS -lt $end ]; do
echo "frank"
if [ $state == "unknown" ]; then
state=$(statecheck)
fi
if [ $state == "meeting" ]; then
while [ -f /media/state/meeting.txt ]; do
sleep 30
done
state=$(cachereset)
fi
if [ $state == "normal" ]; then
while [ -f /media/state/normal.txt ]; do
sleep 30
done
state=$(cachereset)
fi
done

shutdown -r 1






bash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 5 at 15:56









Andy Dalton

4,8391520




4,8391520










asked Sep 5 at 15:22









Dan

61




61




closed as unclear what you're asking by Jeff Schaller, RalfFriedl, Thomas, schily, Archemar Sep 8 at 13:23


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by Jeff Schaller, RalfFriedl, Thomas, schily, Archemar Sep 8 at 13:23


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1




    You may find inotifywait to be useful.
    – ctrl-alt-delor
    Sep 5 at 15:25






  • 2




    an appearance of hanging could result from either of your while [ -f /media/state/... sleep 30 loops, as long as either of those files exist, then bash will do infinite 30-second loops. Is that what your set -x output is indicating?
    – Jeff Schaller
    Sep 5 at 15:38






  • 1




    To execute a bash script in debug mode prepend the script by -x: bash -x yourscript that way you can see what the script is doing and where it enters a loop or blocks.
    – YoMismo
    Sep 6 at 6:47










  • @JeffSchaller the script is meant to loop indefinitely whilst the file is still present (well for 5 days while the main loop still runs) the issue is that looking at the debug output will run perfectly until after the first time state=$(statecheck) runs and then there's no further output. Changing the file that it monitors doesn't result in any changes either.
    – Dan
    Sep 7 at 15:20










  • What's the last line from set -x before it hangs?
    – Jeff Schaller
    Sep 7 at 19:57












  • 1




    You may find inotifywait to be useful.
    – ctrl-alt-delor
    Sep 5 at 15:25






  • 2




    an appearance of hanging could result from either of your while [ -f /media/state/... sleep 30 loops, as long as either of those files exist, then bash will do infinite 30-second loops. Is that what your set -x output is indicating?
    – Jeff Schaller
    Sep 5 at 15:38






  • 1




    To execute a bash script in debug mode prepend the script by -x: bash -x yourscript that way you can see what the script is doing and where it enters a loop or blocks.
    – YoMismo
    Sep 6 at 6:47










  • @JeffSchaller the script is meant to loop indefinitely whilst the file is still present (well for 5 days while the main loop still runs) the issue is that looking at the debug output will run perfectly until after the first time state=$(statecheck) runs and then there's no further output. Changing the file that it monitors doesn't result in any changes either.
    – Dan
    Sep 7 at 15:20










  • What's the last line from set -x before it hangs?
    – Jeff Schaller
    Sep 7 at 19:57







1




1




You may find inotifywait to be useful.
– ctrl-alt-delor
Sep 5 at 15:25




You may find inotifywait to be useful.
– ctrl-alt-delor
Sep 5 at 15:25




2




2




an appearance of hanging could result from either of your while [ -f /media/state/... sleep 30 loops, as long as either of those files exist, then bash will do infinite 30-second loops. Is that what your set -x output is indicating?
– Jeff Schaller
Sep 5 at 15:38




an appearance of hanging could result from either of your while [ -f /media/state/... sleep 30 loops, as long as either of those files exist, then bash will do infinite 30-second loops. Is that what your set -x output is indicating?
– Jeff Schaller
Sep 5 at 15:38




1




1




To execute a bash script in debug mode prepend the script by -x: bash -x yourscript that way you can see what the script is doing and where it enters a loop or blocks.
– YoMismo
Sep 6 at 6:47




To execute a bash script in debug mode prepend the script by -x: bash -x yourscript that way you can see what the script is doing and where it enters a loop or blocks.
– YoMismo
Sep 6 at 6:47












@JeffSchaller the script is meant to loop indefinitely whilst the file is still present (well for 5 days while the main loop still runs) the issue is that looking at the debug output will run perfectly until after the first time state=$(statecheck) runs and then there's no further output. Changing the file that it monitors doesn't result in any changes either.
– Dan
Sep 7 at 15:20




@JeffSchaller the script is meant to loop indefinitely whilst the file is still present (well for 5 days while the main loop still runs) the issue is that looking at the debug output will run perfectly until after the first time state=$(statecheck) runs and then there's no further output. Changing the file that it monitors doesn't result in any changes either.
– Dan
Sep 7 at 15:20












What's the last line from set -x before it hangs?
– Jeff Schaller
Sep 7 at 19:57




What's the last line from set -x before it hangs?
– Jeff Schaller
Sep 7 at 19:57















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?