Executing bash script on wakeup - linux

Since some time I have a Prolbem with my Linux distribution (Kubuntu 18.04). Every time my linux comes back from standby modus the touchpad is not working properly anymore (can't grab and drag files or other objects).
I already found a solution for my Problem:
modprobe psmouse -r
modprobe psmouse
This code does solve the problem. However, after this the rightclick area which I always disable at sartup is enabled again.
I have a script that runs on startup which executes the following:
synclient RightButtonAreaLeft=0
synclient RightButtonAreaTop=0
What I am now trying to do, is to write a script that runs whenever the system is waking up form standby modus.
I wrote the script like this:
#!/bin/bash
exec 1> /home/luc/Schreibtisch/update.log 2>&1
set -x
case $1/$2 in
pre/*)
echo "Going to $2..."
# Place your pre suspend commands here, or `exit 0`
# if no pre suspend action required
exit 0
;;
post/*)
echo "Waking up from $2..."
sh /home/luc/Schreibtisch/test.sh
sh /home/luc/Schreibtisch/test2.sh
;;
esac
Where test.sh runs the modprobe commands and test2.sh runs the synclient commands.
After going to standby modus and waking up again I'm getting the following log:
+ case $1/$2 in
+ echo 'Waking up from suspend...'
Waking up from suspend...
+ sh /home/luc/Schreibtisch/test.sh
+ sh /home/luc/Schreibtisch/test2.sh
Failed to connect to X Server.
Failed to connect to X Server.
And the grabing and draging of the files works perfectly but the rightclick is still enabled.
My question is now if it is possible to execute the synclient commands after the X Server is ready?
Kind regards
Pepsilon

It looks like i have found a workaround for the problem of the touchpad not working properly after wakeup.
In my /etc/modprobe.d/blacklist.conf the module i2c_i801 was blacklisted.
After removing this module form the blacklist my touchpad now works fine after standby mode.

Related

No cursor motion capability occurs when startup linux script execute minicom script with at commands

I have created a startup Linux script for a board that runs Debian jessie Armbian 8.1. I need at startup to run at command in a modem attached to it via USB interface. I've put the script inside rc.local:
#!/bin/sh -e
cd /home/user/Script/
sh script.sh
exit 0
In the folder Script I have a script:
#!/bin/sh
minicom -S at_command.txt
The at_command contains:
send at+creg=1
send exit
! killall minicom
The issue is that when I run the script manually it works correctly,
however when I start the the board the at commands do not execute.
Since the board is Debian I also followed the link: ttp://www.stuffaboutcode.com/2012/06/raspberry-pi-run-program-at-start-up.html and to adapt the script to run according LSBInitScripts but I got the same behavior. When running sudo /etc/init.d/myScript start manually everything works great, but after Linux startup no at_command is executed. I added in the rc.local the following commands for debugging:
set -x;
exec 2>>/home/user/Script/minicom-rc.log;
date +"$0 %c" >&2
And in the generated log file I got this printout:
+ date +/etc/rc.local %c
/etc/rc.local Fri 02 Mar 2018 04:02:43 PM EET
+ cd /home/user/Script/
+ sh script.sh
No cursor motion capability (cm)
What I have done wrong?
I am guessing it is related to there being no terminal during startup.
Maybe try adding the following line before starting minicom:
export TERM=linux-c-nc
In this scenario you alternatively use my atinout program which is a program specifically made for sending AT commands to a modem from the command line (assuming the modem is /dev/ttyUSB0):
echo at+creg=1 | atinout - /dev/ttyUSB0 -
or possibly
atinout /home/user/at_commands.txt /dev/ttyUSB0 /dev/null

Script runs fully when ran manually but misses commands when ran from another script

I have 2 scripts that I'm testing to automate starting services on my server however they behave weirdly.
The first script is
#!/bin/sh
screen -dmS Test_Screen
sleep 1
sudo sh cd.sh
echo "finished"
Which runs perfectly however the script it runs does not and is as follows
#!/bin/sh
screen -S Test_Screen -X stuff "cd /home/Test"
sleep 1
screen -S Test_Screen -X eval "stuff \015"
sleep 1
echo "Complete"
The second script will run perfect if I run it from command line and will CD into the directory within the screen. However, if it runs from the first script it Will Not CD into the correct directory within the screen, but it will still print "Complete".
I'm Using CENTOS 6.7 and the latest version of GNU screen
Any Ideas?
This seems to be a problem with session nesting.
In your first script you create a session named Test_Screen.
In your second script the -S parameter tells screen to create a session of the same name. This might cause screen to exit and not cd into the correct directory.
You could move the cd command in front of the sudo sh cd.sh and remove those screen calls from the second script leaving only
stuff \015
echo "Complete"
Using the correct screenflags should also work.
#!/bin/sh
screen -dr Test_Screen -X stuff "cd /home/Test"
sleep 1
screen -dr Test_Screen -X eval "stuff \015"
sleep 1
echo "Complete"
For a more modern alternative to screen, have a look at tmux.
Ok so this turned out really weird. After posting i tried a couple of things on a centos 6.7 hyper V test environment and got the exact same issue. However, later in the day we ended up changing service provider and upgrading to centos 7 in the process. I am not sure why but since the update the script now runs perfectly and i was able to actually merge the two scripts into one in order to make it more efficient. If anyone knows why the update fixed it feel free to let me know.

Linux - shutdown-script with SSH

I would like to make a shutdown-script for my raspberry pi to shut down anothe raspberry pi over ssh.
The script works if it is running itself but at the shutdown routine the ssh command is not executed.
So that I have done until now:
Made the script in /etc/init.d:
#!/bin/sh
# the first thing is to test if the shutdown script is working
echo "bla bla bla " | sudo tee -a /test.txt
ssh pi#10.0.0.98 sudo shutdown -h now
Made it executable
sudo chmod +x /etc/init.d/raspi.sh
Made a symlink to the rc0.d
sudo ln -s /etc/init.d/raspi.sh /etc/rc0.d/S01raspi.sh
Now I know so far that the shutdown script is working outside of the shutdown routing by calling itself and the shutdown symlink I made is also working partially because I see the changes in the test.txt file every time I shut down.
Can anyone help me how to solve my problem?
Have you tried with single quotes?
The first link in Google has it
http://malcontentcomics.com/systemsboy/2006/07/send-remote-commands-via-ssh.html
What about the sudo, how do you solve entering the password?
https://superuser.com/questions/117870/ssh-execute-sudo-command
Please check this or other links on the web that have useful information.
I would have send all this in a comment but I cant yet because of reputation.
I have now got the script running by myself. I do not really know why it is now working but I write it down beneath and maybe someone else can clearifiy it.
I don´t think the first two changes at my system makes a difference but I also write it down. In the meanwhile because I do not managed the script to get working I had made a button to shutdown the system manually. Also I made a script which backs the mysql-database up (which is on the Raspberry Pi which I would like to switch off with the script) and copies the backup to the raspberry pi which should switch of the other raspberry automatically via the shutdown-script. This happens with scp and also for the password is a key generated.
I have also changed my script to get a log-message out of the script.
#!/bin/sh
ssh -t -t pi#10.0.0.99 'sudo shutdown -h now' >> /home/osmc/shutdown.log 2>&1
To get it into the shutdown-routine I used:
sudo update-rc.d raspi-b stop 01 0
I hope somebody can say me why my code now worked on the first day but not on the next few days until now.
I structured a command to suspend or shutdown a remote host over ssh. You may find this useful. This may be used to suspend / shutdown a remote computer without an interactive session and yet not keep a terminal busy. You will need to give permissions to the remote user to shutdown / suspend using sudo without a password. Additionally, the local and remote machines should be set up to SSH without an interactive login. The script is more useful for suspending the machine as a suspended machine will not disconnect the terminal.
local_user#hostname:~$ ssh remote_user#remote_host "screen -d -m sudo pm-suspend"
source: कार्यशाला (Kāryaśālā)

Autostart JavaFX Application on RaspberryPi

I programmed a JavaFX application which runs on a "Raspberry Pi" (a small ARM based Linux Computer). The OS on the "Pi" is "Raspbian" (a Debian Linux for Raspberry Pi). I installed JDK8 on Raspbian to run graphic JavaFX Application without X-Server. This all works fine :) I can start the Application by entering the following command:
/opt/jdk1.8.0/bin/java -cp /home/pi/sqljdbc4.jar:/home/pi/Leitwarte.jar leitwarte.Leitwarte
When the application starts it takes full control over mouse an keyboard, so there is no way back into console, but this doesent maters because it is just a monitoring system an i am able to shut the mashine down over ssh.
I now want to start the application directly after booting, so that there is no need for entering username ,passwort and starting the application.
The mashine does nothing else just running the app (of course there runs a ftp, ssh deamon for making updating the app posible)
Please tell me step by step, because i dont work with Linux for a long time.
Thank you very much.
CMD
cd /etc/init.d
sudo nano leitwarte
Enter the following
#! /bin/sh
# /etc/init.d/leitwarte
touch /var/lock/leitwarte
case "$1" in
start)
echo "Starting Leitwarte ... "
/opt/jdk1.8.0/bin/java -cp /home/pi/sqljdbc4.jar:/home/pi/Leitwarte.jar leitwarte.Leitwarte > /dev/null &
;;
stop)
echo "Killing Leitwarte ..."
killall java
;;
*)
echo "Usage: /etc/init.d/leitwarte {start|stop}"
exit 1
;;
esac
exit 0
then
chmod 755 leitwarte
update-rc.d leitwarte defaults
DONE
I solved this problem
When the application starts it takes full control over mouse an
keyboard, so there is no way back into console
by adding quotes ("") and by giving -Djavafx.platform=gtk for DEFAULT_JVM_OPTS.
For example in my case I replaced this code:
DEFAULT_JVM_OPTS=-XX:+UseG1GC -Dmode=prod_w_updates
to this:
DEFAULT_JVM_OPTS="-XX:+UseG1GC -Dmode=prod_w_updates -Djavafx.platform=gtk"
Hope, it will help

commands at ubuntu shutdown

How to execute one or more commands and scripts when ubuntu shutdown? Is there any script like /etc/profile and ~/.bashrc at system starting?
I know linux shutdown may have many causes, in addition to dealing with the kill signal, where can I get for this reason?
Is there any script like /etc/profile and ~/.bashrc at system starting?
The SysV Init scripts (/etc/init.d/*) are invoked at startup. A trivial/easy way to invoke some activity at system startup is to put it into /etc/init.d/local (/etc/rc.local for some other distros). See also: RcLocalHowto.
How to execute one or more commands and scripts when ubuntu shutdown?
It sounds as if you want to create a real init script that gets started on entering runlevels X-Z and stopped on exiting them. See also: UbuntuBootupHowto.
I know linux shutdown may have many causes, in addition to dealing with the kill signal, where can I get for this reason?
To do this noninteractively is not straightforward. You can grep through the system logs, looking for indications from shutdown.
There is a ~/.bash_logout file that executes when you log out of Ubuntu 11.04
I am not sure, but assume there is a similar script in 10.04
Hope this helps.
You can put your script in /etc/rc0.d (for halt) and /etc/rc6.d/ (for reboot). Make sure script has executable permission.
There is differents run level :
* 0 System Halt
* 1 Single user
* 2 Full multi-user mode (Default)
* 3-5 Same as 2
* 6 System Reboot
Run level 0 is the system halt condition. When run level 0 is reached all scripts in /etc/rc0.d are exectute.
Run level 6 is used to signal system reboot. This is the same as run level 0 except a reboot is issued at the end of the sequence instead of a power off.
If you want to execute your script on hibernate or on sleep, put your script in /etc/pm/sleep.d/
This is a example of script :
#!/bin/sh
WLANSTATUS=`cat /sys/class/ieee80211/phy*/rfkill*/state`
test -z $WLANSTATUS && exit 1
case $1 in
hibernate)
# Do something before hibernate
;;
suspend)
# Do something before sleep
;;
thaw)
# Do something after hibernate
;;
resume)
# Do something after sleep
if [ $WLANSTATUS = 0 ]; then
echo 0 > /sys/devices/platform/asus_laptop/wlan
elif [ $WLANSTATUS = 1 ]; then
echo 1 > /sys/devices/platform/asus_laptop/wlan
fi
;;
*) echo "somebody is calling me totally wrong."
;;
esac
Have fun !

Resources