How to change desktop background in Linux using Cron [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I found Terminal command to change desktop wallpaper:
gsettings set org.gnome.desktop.background picture-uri file:///path/to/your/image.png
but this command not working in cron and other desktops like Mate. pgrep gnome-session approach shows nothing for me.

You can use dconf to change background. Here is example of simple bash script:
#!/bin/bash
WP="$(find ~+ -type f -exec mimetype {} + 2>/dev/null | awk -F': +' '{ if ($2 ~ /^image\//) print $1 }' | sort -R | tail -30 | shuf -n 1)"
dconf write /org/mate/desktop/background/picture-filename "'${WP}'"
You can find distro-specific key using GUI app - dconf-editor
But to use this script in CRON you need to set session environment variables. Command pgrep gnome-session doesn't work in Mint and other not Gnome desktops. To solve this problem you need to save environment variables of specific user by running command at system startup:
env > ~/cronenv && sed -i '/%s/d' ~/cronenv
now you have cronenv file (without substitutional vars - %s) in users home dir. Just restore them back in cron before running dconf:
*/1 7-21 * * * cd ~/Pictures && env $(cat ~/cronenv | xargs) /path/to/first/script
Use crontab -e to edit cron jobs for current user. All works fine!

Related

Script won't execute on crontab [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I have a script which executes manually:
#!/bin/bash
mount -t cifs //192.168.138.18/Shared_Drive /mnt/share -o username=user,password=guest
But sudo crontab -e doesn't execute it. I tried:
#reboot /home/user/startup.sh
#reboot sh /home/user/startup.sh
#reboot bash -l /home/user/startup.sh
#reboot /bin/bash /home/user/startup.sh
Nothing works. Permits are:
-rwxr-x--x 1 user user
crontab -e doesn't execute scheduled command, it opens your crontab rules file in an editor
The command will then be executed by cron itself on the specified schedule. (If the rule is written correctly. If you want help checking that then include the cron rule.)
Also note that the crontab command man page says
Note that su(8) can confuse crontab and that if you are running inside of su(8) you should always use the -u option for safety's sake
So you should run sudo crontab -u root -e

Bash script check permissions to run command on remote [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I have a local development machine and from my bash script am sending commands to the remote server.
How can I write bash code to check if I am allowed to run the remote command so that I can handle the success/failure response from my script?
Alternatively, how can I capture the output so that I can parse it and detect if it succeeded. The difficulty with parsing is that the ssh command might trigger a password prompt so I can't interfere with that.
That bash script uses ssh -qt to send the remote commands
Command
ssh user#host -qt "sudo -u www /usr/local/bin/php /mnt/data/script.php"
Output:
[sudo] password for xxx:
Sorry, user xxx is not allowed to execute '/usr/local/bin/php /mnt/data/script.php' as www on host.domain.com
Assuming that user != root above: you can't - there's no way to read /etc/sudoers or /etc/sudoers.d/* in a normally set-up Linux box if you're not root, so apart from trial & error there's nothing to be done.
As for capturing the result - that's fairly simple (parsing it, of course, is a different story, depending on what you're doing over there).
output=$( ssh user#host -qt "sudo -u www /usr/local/bin/php /mnt/data/script.php" 2>&1 )
After the execution (and you typing the password for sudo)
echo $? # gives you the return-code of what happened on the far end, if it's a success that should be 0
echo $output # gives you the strings to parse

Keep process running on remote machine after exiting ssh session inside bash script [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
I have a bash script in which I login to a remote machine over ssh and run iperf and then logout and do other things locally. I want iperf to keep running after the bash script logs out. I have tried nohup, disown and setsid, but they don't seem to work when I use them inside the bash script. I have also tried running iperf inside another script, that didn't work either.
Here's the part of the script with nohup example:
ssh root#10.101.10.35 &>/dev/null & << EOF
nohup iperf -s -B 192.168.99.1 &>/dev/null &
EOF
You need to redirect stdin, stdout and stderr to somewhere else as opposed to your terminal like so:
ssh root#10.101.10.35 'iperf -s -B 192.168.99.1 < /dev/null > /tmp/iperf_combined.log 2>&1 &'
stdin is taken from /dev/null (nothing is entered)
stdout and stderr goes to /tmp/iperf_combined.log
The process will run on the remote machine until you will manually kill it or until the script/command will exit on its own.
Edit (as a reply to the poster's comment):
If you want to run multiple commands in the same ssh session, you may use:
ssh -T root#10.101.10.35 << EOF
iperf -s -B 192.168.99.1 < /dev/null > /tmp/iperf_combined_1.log 2>&1 &
iperf -s -B random_ip2 < /dev/null > /tmp/iperf_combined_2.log 2>&1 &
EOF
As per ssh man page:
-T Disable pseudo-tty allocation.
Detailed explanation on psqudo-tty here

How to kill certain process running more than 36 hours and containing certain phrasse in its command? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
on the Linux (CentOS 6), i want to kill process containing "pkgacc" in its command (so no exact command but just partial match) if it is running more than 36 hours.
There is related question: How do you kill all Linux processes that are older than a certain age? but any of the solutions provided do not work for me.
when executing:
if [[ "$(uname)" = "Linux" ]];then killall --older-than 1h someprocessname;fi
It just return killall usage page on how to use killall, in its manual page there is no mention about "--older-than" switch.
It is infinitely easier to invoke a program in a wrapper like timeout from GNU coreutils than to go hunting for them after the fact. In particular because timeout owns its process, there is no ambiguity that it kills the right process. Thus
timeout 36h pkgaccess --pkg_option --another_option package_name
where I made up the names and options for the pkgaccess command since you didn't give them. This process will run no longer than 36 hours.
I think you could do something like
ps -eo pid,cmd,etime
then you could parse the output with grep searching for you process,
something like that:
ps -eo pid,cmd,etime | grep pkgacc
you will have some output with one or more result, the last column from the output must be the time of running process, so one more little bash effort
and you could check if the time is greater than 36 hours.
#!/bin/bash
FOO=$(ps -eo pid,cmd,etime | grep -m 1 pkgacc | awk '{ print $1" "$3 }'| sed -e 's/\://g')
IFS=' ' read -r -a array <<< "$FOO"
if [ "${array[1]}" -gt "360000" ]; then
echo "kill the process: ${array[0]}"
else
echo "process was not found or time less than 36 hours"
fi
I think that could solve part of your problem,
see that I do not explicit kill the process but just indicate
what it is. You could improve the idea from that.

Issue with changing login shell [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I want to change the default login shell on my Ubuntu.
To change the shell I ran the following:
$ chsh -s /usr/bin/zsh
After that I restart my terminal but my default shell is still bash.
$ echo $SHELL
/bin/bash
These are shells installed on my machine:
$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
/bin/zsh
/usr/bin/zsh
Record for my user in /etc/passwd is also changed like expected:
$ cat /etc/passwd|grep myuser
myuser:x:1000:1000:myuser,,,:/home/myuser:/usr/bin/zsh
I successfully changed my login shell the same way on my mac but I seem to be having some issue on Ubuntu. Am I missing something here?
You need to logout and log back into Ubuntu so that your GUI based X terminal shells pick up the new shell value.
Note: Ctrl+Alt+F[1-6] represent 6 virtual shells while GUI login is on Ctrl+Alt+F7

Resources