Looking for script to execute commands in a loop [Solved]
Looking for script to execute commands in a loop [Solved]
I need a script which would execute several commands one by one in a circle with still the same keystroke. Similar to Rox when pressing repeatedtly "Sort by...". I am sure there are many hints on the web, but I canˇt find the right one.
Last edited by riedzig on Fri 03 Jan 2020, 09:01, edited 1 time in total.
Hi riedzig.
What do you mean "in a circle"? What do you want to do with it?
Sounds like you wish to create a virus!!!
Simplest sample:
You could also use a number of loops, even make it run unattended.
But I'll stop here and ask you to make your intentions clear!
BFN.
What do you mean "in a circle"? What do you want to do with it?
Sounds like you wish to create a virus!!!
Simplest sample:
Code: Select all
#/bin/sh
# /root/my-applications/bin/k.sh # make a symlink to k
# so when you hit the k key in console, it will run.
1stCommand
2ndCommand
3rdCommand
# etc.
exit
But I'll stop here and ask you to make your intentions clear!
BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
This one will loop, if that helps ..
cmd-loop.sh:
cmd-loop.sh:
Code: Select all
#! /bin/bash
#
# Looping commands
#
LoopFile="taskloop.txt"
if [ ! -e $LoopFile ]; then echo "1" > $LoopFile; fi
Task=$(cat $LoopFile)
case "$Task" in
1) printf "\tCommand 1\n"
echo "2" > $LoopFile
;;
2) printf "\tCommand 2\n"
echo "3" > $LoopFile
;;
3) printf "\tCommand 3\n"
echo "1" > $LoopFile
;;
*)
# do nothing
;;
esac
This is even more fun. Get a bunch of them on your screen and watch them disappear.
cmd-loop.sh:
cmd-loop.sh:
Code: Select all
#! /bin/bash
#
# Looping commands
#
LoopFile="taskloop.txt"
if [ ! -e $LoopFile ]; then echo "1" > $LoopFile; fi
Task=$(cat $LoopFile)
case "$Task" in
1) yad --info --timeout=30 --height=100 --width=100 --center --title="Command looper" --text="Command one!" &
echo "2" > $LoopFile
;;
2) yad --info --timeout=30 --height=100 --width=100 --center --title="Command looper" --text="Command two!" &
echo "3" > $LoopFile
;;
3) yad --info --timeout=30 --height=100 --width=100 --center --title="Command looper" --text="Command three!" &
echo "1" > $LoopFile
;;
*)
# do nothing
;;
esac
Thanks jafadmin
I think your first script might help, but I'm halfway.
How would it precisely look if:
The first executing the script opens e.g. roxfiler
Second kills roxfiler and opens geany
Third kills geany and opens leafpad
Fourth kills leafpad and opens again roxfiler
or for display rotating:
1. xrandr -o left
2. xrandr -o inverted
3. xrandr -o right
4. xrandr -o normal
5. xrandr -o left and so on
I think your first script might help, but I'm halfway.
How would it precisely look if:
The first executing the script opens e.g. roxfiler
Second kills roxfiler and opens geany
Third kills geany and opens leafpad
Fourth kills leafpad and opens again roxfiler
or for display rotating:
1. xrandr -o left
2. xrandr -o inverted
3. xrandr -o right
4. xrandr -o normal
5. xrandr -o left and so on
Just extend the "case" statement.
i.e.: replace the "printf" command lines with your own "xandr" command lines. Add more cases for however many commands you need.
The "echo" lines control the indexing. The last "echo" command sets it back to 1
.
i.e.: replace the "printf" command lines with your own "xandr" command lines. Add more cases for however many commands you need.
Code: Select all
case "$Task" in
1) xrandr -o left # <- your command
echo "2" > $LoopFile # <- required indexer
;;
2) xrandr -o inverted
echo "3" > $LoopFile
;;
3) xrandr -o right
echo "4" > $LoopFile
;;
4) xrandr -o normal
echo "1" > $LoopFile # <- set index back to 1
;;
*);; # Ignore anything else
esac
.
The xrandr variant works perfectly.
Then I adapted your script to a working "slideshow" for xplanet which is a great app with many config options (scripts named xplanet1, xplanet2 and so on).
Now I am trying to combine the commands with killing the previous xplanet
1) killall xplanet;xplanet1
echo "2" > $LoopFile
;;
2) killall xplanet;xplanet2
echo "3" > $LoopFile
;;
3) killall xplanet;xplanet3
echo "4" > $LoopFile
;;
4) killall xplanet;xplanet4
echo "1" > $LoopFile
;;
This would also work except each script is being executed 2 times:
xplanet1
xplanet1
xplanet2
xplanet2
xplanet3 etc
What am I doing wrong?
Then I adapted your script to a working "slideshow" for xplanet which is a great app with many config options (scripts named xplanet1, xplanet2 and so on).
Now I am trying to combine the commands with killing the previous xplanet
1) killall xplanet;xplanet1
echo "2" > $LoopFile
;;
2) killall xplanet;xplanet2
echo "3" > $LoopFile
;;
3) killall xplanet;xplanet3
echo "4" > $LoopFile
;;
4) killall xplanet;xplanet4
echo "1" > $LoopFile
;;
This would also work except each script is being executed 2 times:
xplanet1
xplanet1
xplanet2
xplanet2
xplanet3 etc
What am I doing wrong?