How can I make this bash xautolock script works? - bash

H_i guys, I'm running Arch with i3 as WM, i3lock works fine when manually executed via keybinding, xautolock is ofc installed and the script is launched at startup ( when trying to manually launch it I get this message : " xautolock is already running (PID 1302)" but my screen never automatically locks
Here is the script :
#!/bin/sh
exec xautolock -detectsleep \
-time 3 -locker "i3lock -d -c 000000" \
-notify 30 \
-notifier "notify-send -u critical -t 10000 -- 'LOCKING screen in 30 seconds'"
Thanks in advance.

Related

Terminal script involving 2 terminals

Is it possible to make a command that does something, Opens another terminal and then does something there?
Im trying to combine the start up of a server and its api.
"god": "next dev && cd server && strapi develop"
I want the 'cd' part to start in a new terminal. Ive tried open -a terminal but it doesnt seem to work.
you can try to use tmux for that
tmux new-session \; \
send-keys 'next dev' C-m \; \
split-window -h -p 50 \; \
send-keys 'cd server && strapi develop' C-m \;
If I understand the question correctly, you simply need to run two commands in parallel. This can be achieved easily in bash:
command1 & command2 # will run command1, send it to background,
# and run command2 (which will be kept in foreground)
In your case:
next dev & cd server && strapi develop
You can read more about this here: How do you run multiple programs in parallel from a bash script?

how to send minicom to background?

I need to log some data from a serial device. So I would like to first call minicom with the & parameter:
minicom -D /dev/ttyXYZ -b 115200 -C logFile &
But taking a look to ps aux shows, that minicom had become a terminated zombie process:
edeviser 8835 0.0 0.0 19696 2628 pts/0 T 15:29 0:00 minicom -D /dev/ttyXYZ -b 115200 -C logFile
How to send minicom to background?
Further information:
I would like to send it to background because I'll need to trigger some actions after minicom has started to log the serial data to the logFile. Using cat /dev/ttyXYZ > logFile is no option, because I must specify the baudrate. Using a second terminal is also no option, because this work will be done by a bash script.
Have you tried:
nohup minicom -D /dev/ttyXYZ -b 115200 -C logFile &
I ran into the same issue when I was trying to convert movies with handbrake-cli.
nohup will background the task and push the output into a txt file called nohup.txt.

Need to run chromium as normal user from root script

I have a kiosk that shuts down every day using rtcwake, and this uses root user. I've used && to execute the boot script after rtcwake completes, however it then starts the browser as root causing problems.
This is the command I use:
echo debian | sudo -S rtcwake -m mem -u -t $(date +%s -d '3 days 7:45') && sudo -u debian -i bash $HOME/kiosk/bin/startup.sh &.
The sudo command does work to some extent. It calls the debian user, and executes the correct script, however, it still screws up my chromium preferences.
Here is the startup script:
echo debian | sudo -S hwclock -w
export HOME=/home/debian
#log boot time
echo "Booting at" $(date) >> $HOME/kiosk/bin/logs/boot.log
#echo debian | sudo -S service connman restart
echo debian | sudo -S at 15:30 -f $HOME/kiosk/bin/shutdown.sh
crontab -u debian crontab.txt
bash $HOME/git.sh
#sudo -i -u debian
#start kiosk
export DISPLAY=:0
chromium-browser --kiosk --disable-gpu
http://localhost/kiosk/Client/main.html &
#update ip
bash /home/debian/git.sh &
I'm wondering what could be causing chrome to be executed as root. I have no idea what is going wrong.
If you execute a command with sudo it will not change environment variables like $HOME. Since per user settings are stored in $HOME, this affects the executed program if it needs such configuration files. Check this for example:
sudo -u debian bash -c 'echo $HOME'
It will print the home folder of the calling user, not the home folder of the user specified trough -u. The sudo command supports the -H command line option to handle this, however if it works depends on the security police in use.
As a solution you can use the su command instead of sudo in this case:
... && su debian -c chromium
Since su itself is executed by root you won't be asked for the password.
You must enter a password to log into a new user shell.
The command needs to be modified as follows:
echo debian | sudo -S rtcwake -m mem -u -t $(date +%s -d '3 days 7:45') && echo debian | sudo -S -u debian -i bash $HOME/kiosk/bin/startup.sh &
This avoids needing a password to log in as normal Debian user, and executes the script.

Why docker exec is killing nohup process on exit?

I have running docker ubuntu container with just a bash script inside. I want to start my application inside that container with docker exec like that:
docker exec -it 0b3fc9dd35f2 ./main.sh
Inside main script I want to run another application with nohup as this is a long running application:
#!/bin/bash
nohup ./java.sh &
#with this strange sleep the script is working
#sleep 1
echo `date` finish main >> /status.log
The java.sh script is as follow (for simplicity it is a dummy script):
#!/bin/bash
sleep 10
echo `date` finish java >> /status.log
The problem is that java.sh is killed immediately after docker exec returns. The question is why?
The only solution I found out is to add some dummy sleep 1 into the first script after nohup is started. Than second process is running fine. Do you have any ideas why it is like that?
[EDIT]
Second solution is to add some echo or trap command to java.sh script just before sleep. Than it works fine. Unfortunately I cannot use this workaround as instead of this script I have java process.
This is not an answer, but I still don't have the required reputation to comment.
I don't know why the nohup doesn't work. But I did a workaround that worked, using your ideas:
docker exec -ti running_container bash -c 'nohup ./main.sh &> output & sleep 1'
Okay, let's join two answers above :D
First rcmgleite say exactly right: use
-d
options to run process as 'detached' background.
And second (the most important!) if you run detached process, you don't needed nohup!
deploy_app.sh
#!/bin/bash
cd /opt/git/app
git pull
python3 setup.py install
python3 -u webui.py >> nohup.out
Execute this inside a container
docker exec -itd container_name bash -c "/opt/scripts/deploy_app.sh"
Check it
$ docker attach container_name
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 11768 1940 pts/0 Ss Aug31 0:00 /bin/bash
root 887 0.4 0.0 11632 1396 pts/1 Ss+ 02:47 0:00 /bin/bash /opt/scripts/deploy_app
root 932 31.6 0.4 235288 32332 pts/1 Sl+ 02:47 0:00 python3 -u webui.py
I know this is a late response but I will add it here for documentation reasons.
When using nohup on bash and running it with 'exec' on a docker container, you should use
$ docker exec -d 0b3fc9dd35f2 /bin/bash -c "./main.sh"
The -d option means:
-d, --detach Detached mode: run command in the
background
for more information about docker exec, see:
https://docs.docker.com/engine/reference/commandline/exec/
This should do the trick.

Keep the gnome terminal open after the program is finished

This script opens a gnome terminal and 4 tabs in it , but once the program finishes the tabs gets closed so i can't see the output. It doesn't happen when i run each program manually. How can keep the tab open , even when the program is finished .
gnome-terminal --tab -e "optirun yarpserver" \
--tab -e "sh -c 'sleep 20 ; optirun iCub_SIM'" \
--tab -e "sh -c 'sleep 86 ; optirun simCartesianControl'" \
--tab -e "sh -c 'sleep 116 ; optirun iKinCartesianSolver --context simCartesianControl/conf --part left_arm'" \
Not sure how to do it on the command line (man gnome-terminal doesn't seem to indicate a specific option for that, but you can start a gnome-terminal, set specific options (one of which would be "When command exits: Hold the terminal open"), and save your settings as a specific profile. There is a command-line option for selecting a specific profile to use, so that should accomplish what you want.

Resources