LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 07-15-2017, 11:15 AM   #1
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
JWM and thier desktop image options and bash scripts - not doing what it should?


Ok due to two reasons I installed this JWM - one I was already looking for something else to use for a desktop - just for a change - and two: someone in here put me up it it because they did it, so I tried it, and its nice. But,

I use a script to change desktop images (random images) it works, then when I used it in this jwm it works but how this is working it not good.

when one sets jwm up to show a different image on each desktop. it will call to change the image when one changes the desktop so that right image will show when it is suppose to.

The advantages of the tags options one is command, to execute a command instead of an image, therefore scripts too can be used within this option of separate images for each desktop.

my script has within it a means to check PIDS count if more than then kill the extra ones so process will not get over ran and have more than one of these scripts running at a time, therefore keeping the changing of the image on the background to just whatever it is set up to time change in the script.

in other words change time is set to 1 minute that script controls that, but if another run of same script is ran then it changes too.

now two scripts are changing the image at accordance to their start time.
hence kill the extra pids to prevent changing the image more often than 1 minute.


Within my script when executed the function to check PID count and kill PIDS if more than will be called every time the script is called to execute.

The JWM : when ever one changes to the desktop then whatever is within the tags will be called to execute upon change.


So logically when ever I change my desktop to the desktop that executes the script. then upon that script execution it is SUPPOSE to be calling that function that checks PID count.

But something is awry .. it does execute my script every time I change to that desk top, I can tell just by how I got it set up to work.

to set a given image upon execute to take up lag time waiting for a minute to pass before cycle starts to set random images.

then then next thing that is suppose be happening in that script is that function call. which is not being done for some strange reasons.

script is this:
it is not that complicated. Is is only three functions.
Code:
#!/bin/bash


WALLPAPERS=/media/data/wallpaper

## set an image to background immediately
mhsetroot -fs /home/userx/Dropbox/wallpaperbackups/mixed/C186.jpg


KillPid(){
#get App name
appname=$0
appname=${appname#*/}

#find pids to kill to prevent over running process with same script

if [[ $(pgrep -u $USER $appname | wc -l) -ge 2 ]] && [[ $( pgrep -u $USER sleep | wc -l) -ge 1 ]] ; then
  {
    #get PID for script
    echo "$appname had pids : $(pgrep -u $USER $appname)"
    echo;echo;echo
    PID2KILL="$(pgrep -u $USER $appname)"
    echo "before cut PID: $PID2KILL"
    PID2KILL=${PID2KILL#* }
    echo "PIDS : $PID2KILL"
    echo;echo;echo
  
    #get PID for sleep
    SPID2KILL="$(pgrep -u $USER sleep)"
    echo "before cut SPID: $SPID2KILL"
    SPID2KILL=${SPID2KILL#* }
    echo "SPIDS : $SPID2KILL"
  
    #kill the extra PIDs   
    kill $SPID2KILL
    kill $PID2KILL
    
    echo "SPID is: $(pgrep -u $USER sleep)"
    
  }
  else
  {
    echo "running pid is : $(pgrep -u $USER $appname)"
  }
fi
}

#added function call here to try and force it to check 
# right after image set in above lines

KillPid

#get a color
color() {
echo \#$(head -n 1 /dev/urandom | od -t x1 -N 9 | awk '{print $2 $3 $4}')
}
ImgNum1()
{
  #shuffel between High - Low range
  ImgsizeNum1=$(($RANDOM % 200 + 200 | bc ))

  ImgsizeNum2=$(($RANDOM % 200 + 300 | bc ))

  ImageDimentions="$ImgsizeNum1"x"$ImgsizeNum2"
  echo $ImageDimentions
}



startChanging()
{

while true 
do
     SetSubDir=$(shuf -i 1-$((($(find "$WALLPAPERS" -type d  | wc -l)-1))) -n 1)
	    
	   WALLPAPERS="$WALLPAPERS/$SetSubDir"
	    
	
		#ImgNum1 #gets ImageDimentions
		
		setShow=$(shuf -i 1-4 -n 1)
		
		case "$setShow" in
		1)
		  Imageis="-fill"
		  ;;
		2)
		  ImgNum1
		  Imageis="-dtile $ImageDimentions"
		  #Imageis="-dtile 300x300"
		  ;;
		3)
		  Imageis="-fimgv"
		  ;;
		4)
		  Imageis="-dcenter $((RANDOM % 100 + 500  | bc ))"x"$((RANDOM % 300 + 800 | bc ))"
		  ;;
		esac
			
		gradientAngle=$((gradientAngle+=10))
		
		[[ $gradientAngle -gt '160' ]] && gradientAngle=1
		
		find "$WALLPAPERS" -type f \( -name '*.jpg' -o -name '*.png' -o -name "*.bmp" \) -print0 | shuf -n 1-$(find "$WALLPAPERS" -type f | wc -l) -z | xargs -0 \
		mhsetroot -add $(color) -add $(color) -gradient $gradientAngle $Imageis 
		
		#find "$WALLPAPERS" -type f \( -name '*.jpg' -o -name '*.png' -o -name "*.bmp" \) -print0 | shuf -n 1-$(find "$WALLPAPERS" -type f | wc -l) -z | xargs -0 \
		 #mhsetroot -addd $(color) 3 -addd $(color2) 5 -addd $(color) 3 -addd $(tint) 8 -gradient "$(setGradient)" $setI $ImageDimentions
		 
		 #mhsetroot -solid $(echo \#$(head -n 1 /dev/urandom | od -t x1 -N 9 | awk '{print $2 $3 $4}'))
  sleep  1m
  
  
done >&2>>/dev/null >> changebgimage.log &

KillPid
}

startChanging
Instead of KillPid() working it just keeps piling up
Code:
 userx%slackwhere ⚡ ~ ⚡> ps aux | grep changebgimage
userx    10367  1.2  0.3 2554220 65008 ?       Sl   10:44   0:01 kwrite file:///home/userx/changebgimage
userx    10703  0.0  0.0  12072  2412 ?        S    10:45   0:00 /bin/bash /home/userx/changebgimage
userx    10718  0.0  0.0  12072  2592 ?        S    10:45   0:00 /bin/bash /home/userx/changebgimage
userx    10779  0.0  0.0  12072  2512 ?        S    10:45   0:00 /bin/bash /home/userx/changebgimage
userx    10810  0.0  0.0  11668  2104 pts/1    S+   10:45   0:00 grep changebgimage
userx%slackwhere ⚡ ~ ⚡> ps aux | grep changebgimage
userx    10367  1.2  0.4 2554748 65648 ?       Sl   10:44   0:02 kwrite file:///home/userx/changebgimage
userx    10703  0.0  0.0  12072  2416 ?        S    10:45   0:00 /bin/bash /home/userx/changebgimage
userx    10718  0.0  0.0  12072  2592 ?        S    10:45   0:00 /bin/bash /home/userx/changebgimage
userx    10779  0.0  0.0  12072  2512 ?        S    10:45   0:00 /bin/bash /home/userx/changebgimage
userx    10908  0.0  0.0  12072  2464 ?        S    10:47   0:00 /bin/bash /home/userx/changebgimage
userx    10983  0.0  0.0  12072  2396 ?        S    10:47   0:00 /bin/bash /home/userx/changebgimage
userx    11015  0.0  0.0  11668  2224 pts/1    S+   10:47   0:00 grep changebgimage
userx%slackwhere ⚡ ~ ⚡>
Of course this works when I run it in a command line.
Code:
userx%slackwhere ⚡ ~ ⚡> pkill changebgimage
userx%slackwhere ⚡ ~ ⚡> ps aux | grep changebgimage
userx    10367  0.2  0.4 2555340 71284 ?       Sl   10:44   0:03 kwrite file:///home/userx/changebgimage
userx    13853  0.0  0.0  11668  2104 pts/1    S+   11:09   0:00 grep changebgimage


userx%slackwhere ⚡ ~ ⚡> ./changebgimage
changebgimage had pids : 13854



before cut PID: 13854
PIDS : 13854
Terminated
userx%slackwhere ⚡ ~ ⚡> 
userx%slackwhere ⚡ ~ ⚡> ./changebgimage
changebgimage had pids : 13864



before cut PID: 13864
PIDS : 13864
Terminated
userx%slackwhere ⚡ ~ ⚡> ps aux | grep changebgimage
userx    10367  0.2  0.4 2555340 71284 ?       Sl   10:44   0:03 kwrite file:///home/userx/changebgimage
userx    13883  0.0  0.0  11668  2140 pts/1    S+   11:10   0:00 grep changebgimage
userx%slackwhere ⚡ ~ ⚡>
the only reason we do not see one instance of the script running now is only because I added the call right after I defined it. as noted above in the code.

If I remove that extra call it works in the command line, as well if I just use it to be called in an "autostart" method in this WM as well as any other Desktop or Window Manager.
Code:
userx%slackwhere ⚡ ~ ⚡> ./changebgimage                                                                             
running pid is : 13891
13893
13895
13898
userx%slackwhere ⚡ ~ ⚡> ps aux | grep changebgimage
userx    10367  0.2  0.4 2555340 71476 ?       Sl   10:44   0:03 kwrite file:///home/userx/changebgimage
userx    13893  0.0  0.0  12064  2512 pts/1    S    11:12   0:00 /bin/bash ./changebgimage
userx    13926  0.0  0.0  11668  2104 pts/1    S+   11:12   0:00 grep changebgimage
userx%slackwhere ⚡ ~ ⚡> ./changebgimage                                                                             
changebgimage had pids : 13893
13927
13929
13931
13934



before cut PID: 13893
13927
13929
13931
13934
PIDS : 13893
13927
13929
13931
13934
Terminated
userx%slackwhere ⚡ ~ ⚡> ps aux | grep changebgimage
userx    10367  0.2  0.4 2555340 71476 ?       Sl   10:44   0:03 kwrite file:///home/userx/changebgimage
userx    13929  0.0  0.0  12064  2516 pts/1    S    11:12   0:00 /bin/bash ./changebgimage
userx    13963  0.0  0.0  11668  2144 pts/1    S+   11:12   0:00 grep changebgimage
userx%slackwhere ⚡ ~ ⚡>
I do hope I have not boggled the minds of anyone with this.

Last edited by BW-userx; 07-15-2017 at 12:07 PM.
 
Old 07-15-2017, 11:50 AM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
SOLVED:
this is the issue:
Code:
userx%slackwhere ⚡ ~ ⚡> ps aux | grep changebgimage
userx    10367  0.2  0.4 2555368 71544 ?       Sl   10:44   0:08 kwrite file:///home/userx/changebgimage
userx    15332  0.0  0.0  12072  2588 pts/1    S    11:44   0:00 /bin/bash ./changebgimage
userx    15373  0.0  0.0  12080  2596 ?        S    11:45   0:00 /bin/bash /home/userx/changebgimage
userx    15432  0.0  0.0  11668  2096 pts/1    S+   11:45   0:00 grep changebgimage
in script bad oops code
Code:
#get App name
appname=$0
appname=${appname#*/}
when WM was calling the function to check with the way I was chopping off the path to appname. It was written for when it was being ran off command line so I was only checking for the ./ one slash. Changed it to take off farthest from left to right.
Code:
#get App name
appname=$0
appname=${appname##*/}
Now it is being stripped to get just the name.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bad desktop BG on Jwm black-clover Linux - Desktop 6 07-14-2017 03:27 PM
Save the state of your desktop and restore it on Openbox/JWM/Fluxbox Xeratul Linux - Desktop 1 01-25-2017 02:17 PM
LXer: Python Scripts as a Replacement for Bash Utility Scripts LXer Syndicated Linux News 1 01-17-2013 08:08 AM
Any JWM experts here? Need advice/help with JWM linus72 Linux - Desktop 2 07-07-2009 04:41 PM
Need to chroot bash users to thier home directory coloradopaul Linux - Security 1 09-16-2004 10:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 09:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration