(OLD) (ARCHIVED) Puppy Linux Discussion Forum Forum Index (OLD) (ARCHIVED) Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info

This forum can also be accessed as http://oldforum.puppylinux.com
It is now read-only and serves only as archives.

Please register over the NEW forum
https://forum.puppylinux.com
and continue your work there. Thank you.

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups    
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 28 Jan 2021, 08:11
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
Looking for script to execute commands in a loop [Solved]
Moderators: Flash, Ian, JohnMurga
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. View previous topic :: View next topic
Page 1 of 1 [10 Posts]  
Author Message
riedzig

Joined: 01 Oct 2015
Posts: 40

PostPosted: Sun 29 Dec 2019, 16:06    Post subject:  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, 05:01; edited 1 time in total
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 15041
Location: Gatineau (Qc), Canada

PostPosted: Sun 29 Dec 2019, 17:16    Post subject:  

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:
Code:
#/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

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! Wink

BFN.

_________________
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
Back to top
View user's profile Send private message 
jafadmin

Joined: 19 Mar 2009
Posts: 1258

PostPosted: Sun 29 Dec 2019, 18:42    Post subject:  

This one will loop, if that helps ..

cmd-loop.sh:
Code:

#! /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
Back to top
View user's profile Send private message 
jafadmin

Joined: 19 Mar 2009
Posts: 1258

PostPosted: Mon 30 Dec 2019, 02:13    Post subject:  

This is even more fun. Get a bunch of them on your screen and watch them disappear.

cmd-loop.sh:
Code:
#! /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
Back to top
View user's profile Send private message 
riedzig

Joined: 01 Oct 2015
Posts: 40

PostPosted: Mon 30 Dec 2019, 04:16    Post subject:  

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
Back to top
View user's profile Send private message 
jafadmin

Joined: 19 Mar 2009
Posts: 1258

PostPosted: Mon 30 Dec 2019, 13:19    Post subject:  

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.
Code:

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 "echo" lines control the indexing. The last "echo" command sets it back to 1

.
Back to top
View user's profile Send private message 
riedzig

Joined: 01 Oct 2015
Posts: 40

PostPosted: Wed 01 Jan 2020, 17:34    Post subject:  

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?
Back to top
View user's profile Send private message 
jafadmin

Joined: 19 Mar 2009
Posts: 1258

PostPosted: Wed 01 Jan 2020, 19:38    Post subject:  

try putting an ampersand '&' after each "xplanet' command: "xplanet3 &"
Back to top
View user's profile Send private message 
riedzig

Joined: 01 Oct 2015
Posts: 40

PostPosted: Thu 02 Jan 2020, 06:06    Post subject:  

Many thanks, & is the solution.
Back to top
View user's profile Send private message 
jafadmin

Joined: 19 Mar 2009
Posts: 1258

PostPosted: Fri 03 Jan 2020, 03:17    Post subject:  

riedzig wrote:
Many thanks, & is the solution.


Go ahead and edit the first post title and add "[Solved] to the title.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [10 Posts]  
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. View previous topic :: View next topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 2.5323s ][ Queries: 11 (2.2547s) ][ GZIP on ]