Debug script


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 8  
According to one of the comments in the link you posted, the correct directory for this on a Debian, and therefore Ubuntu system, is /lib/systemd/system-sleep, not /usr/lib/systemd/system-sleep.

Did you have to create the directory /usr/lib/systemd/system-sleep, or was it there when you started?

Does the directory /lib/systemd/system-sleep exist? What happens if you put your script there?

Did you remember to set the execute attributes on the script?

Try adding the line
Code:
exec 2> /tmp/systemd_suspend_test_err.txt

to the beginning of your script. That should redirect trace output to the file /tmp/systemd_suspend_test_err.txt.

Andrew
This User Gave Thanks to apmcd47 For This Post:
# 9  
The script is in /usr/lib/systemd/system-sleep/.

As per

Running scripts before and after suspend with systemd << Just another Linux geek

It also has the execute bit set.

I found this in syslog.

It seems odd. (The scripts also has no sh extension.)

Code:
Apr  2 06:03:48 7 systemd-sleep[5614]: /lib/systemd/system-sleep/On_Resume.sh: 2: [: post: unexpected operator
Apr  2 06:03:48 7 systemd-sleep[5614]: /lib/systemd/system-sleep/On_Resume.sh: 5: [: post: unexpected operator


Last edited by drew77; 04-02-2019 at 08:06 AM..
# 10  
Quote:
Originally Posted by drew77
The script is in /usr/lib/systemd/system-sleep/.

As per

Running scripts before and after suspend with systemd << Just another Linux geek

It also has the execute bit set.
Read Sampi's response:
Quote:
Other users of Debian might want to take notice that the path to place the files under for that distribution is /lib/systemd/system-sleep/, i.e. without the initial /usr. Although this actually is properly documented with the correct path in the man page, it is a detail which is easy to miss.
So you should be using /lib/systemd/system-sleep/ as you are using Ubuntu, which is a Debian-based system. If you are not using Ubuntu, why are you posting to an Ubuntu sub forum?

Andrew
# 11  
Quote:
Originally Posted by apmcd47
Absolutely! I was about to write the same, you beat me to it.

Quote:
Originally Posted by drew77
The script is in /usr/lib/systemd/system-sleep/.
I found this in syslog.
Code:
Apr  2 06:03:48 7 systemd-sleep[5614]: /lib/systemd/system-sleep/On_Resume.sh: 2: [: post: unexpected operator
Apr  2 06:03:48 7 systemd-sleep[5614]: /lib/systemd/system-sleep/On_Resume.sh: 5: [: post: unexpected operator

Exactly what apmcd47 already said: /lib/systemd/system-sleep/On_Resume.sh is not the same as /usr/lib/systemd/system-sleep/On_Resume.sh and you are simply debugging the wrong script.

I hope this helps

bakunin
# 12  
I put script in correct directory.

No change.

I found this in that dir.

Format looks different.

Code:
#!/bin/sh
set -e

if [ "$2" = "hibernate" ] || [ "$2" = "hybrid-sleep" ]; then
    case "$1" in
        pre)
            /usr/share/unattended-upgrades/unattended-upgrade-shutdown --stop-only
            ;;
    esac
fi

# 13  
Quote:
Originally Posted by drew77
I put script in correct directory.
I am not sure what that means: in post #6 you said your script is named /usr/lib/systemd/system-sleep/On_Resume. You need to not only move it to another directory (which would make it /lib/systemd/system-sleep/On_Resume) but also name it differently: /lib/systemd/system-sleep/On_Resume.sh Have you done both? If yes, there should at least be some message in /tmp/systemd_suspend_test_err.txt now, otherwise your script has most probably NOT run.


Quote:
Originally Posted by drew77
Format looks different.

Code:
#!/bin/sh
set -e

if [ "$2" = "hibernate" ] || [ "$2" = "hybrid-sleep" ]; then
    case "$1" in
        pre)
            /usr/share/unattended-upgrades/unattended-upgrade-shutdown --stop-only
            ;;
    esac
fi

It not only looks differently - it is! It does something completely different: first, this script expects TWO parameters, not just one. If the second is not "hibernate" or "hybrid-sleep", it does simply nothing at all. Second, this script is most probably run by a different shell: /bin/sh instead of bash. Depending on what /bin/sh links to (in Ubuntu perhaps dash) this will not be dash. Third, even if this script would do something (which is now, given the parameters with which you called the first script, unlikely) it would be something completely different from what the first script does.

I hope this helps.

bakunin
# 14  
I thought I posted that my problem was not setting the exe bit, but I could not find the post.

The script does run.

I added this, but it does not run.

I gave the full path.

Code:
/usr/bin/gxmessage -fg red -font  'sans 30' -timeout 3  'Back from being suspended.'

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] How to debug awk script?

how can i view what variables are stored upon the excution of an awk script. something equivalent to shell eg. sh -vx "script_file" many thanks in advance! (1 Reply)
Discussion started by: Apollo
1 Replies

2. Shell Programming and Scripting

Debug perl script

Hi, I am trying to get squid up and running using a redirector process, and every time I try to load a web page, squid fails miserably. Can some one with perl and squid knowledge take a look at these codes and tell if something is wrong here. #!/usr/bin/perl # $| = 1; @endings = qw/... (0 Replies)
Discussion started by: jamie_123
0 Replies

3. Shell Programming and Scripting

Debug script already running

Hello, is it possible to debug a script that is already running "on-demand"? Somehow a command like "set -x" but once you've executed the script. And another one to disable debugging? Thank you (0 Replies)
Discussion started by: asanchez
0 Replies

4. Shell Programming and Scripting

Cant debug shell script

Hi I am relatively new in shell scripting Below is the code which i developed but for some reason, it keeps giving me error: /apps/bss/BatchProg/at1/batch/scripts/ksh/TBATLC02.ksh: syntax error at line 41 : `then' unmatched #!/usr/bin/ksh... (4 Replies)
Discussion started by: scripting_newbe
4 Replies

5. Shell Programming and Scripting

Help with debug the script

Hi, I have this script, searches and sets variables, then searches and sets more variables from multiple files. I'd need to debug it a bit. #!/bin/bash egrep $1 `find | grep MAGT` >/tmp/resRA-$$ thread=`sed -n '/{0x/ {s/^.*{0x\(*\).*/\1/p;q}' /tmp/resRA-$$` tag=`sed -n '/Tag=/... (5 Replies)
Discussion started by: Vitoriung
5 Replies

6. Shell Programming and Scripting

Problem with the script, help me debug

Hi, When i run the script ./script.sh sun, this give me no output, it should give me the list of file. If i run the script without the argument it should send me echo inside usage(). What is the problem? please help -Adsi #!/bin/sh ROOT_PATH=/net/icebox/vol/local_images/spins... (2 Replies)
Discussion started by: asirohi
2 Replies

7. Shell Programming and Scripting

anyone!! debug this small script..thanks in advance..

x="PermitRootLogin no" cd /etc/ssh y=`cat sshd_config |grep "PermitRootLogin"` if ] then print "Sorry, Remote Root SSH login already disabled." exit else print "Welcome to Remote SSH Login disable script." fi output: + x=PermitRootLogin no + cd /etc/ssh + + cat sshd_config... (2 Replies)
Discussion started by: solaix14
2 Replies

8. Shell Programming and Scripting

debug this script

echo "input time in hhmmss" read $st h=`echo $st | cut -c1-2` min=`echo $st | cut -c3-4` s=`echo $st | cut -c5-6` echo "input time in hhmmss" read $end h1=`echo $end | cut -c1-2` min1=`echo $end | cut -c3-4` s1=`echo $end | cut -c5-6` x= `expr $h /* 60 + $min` y= `expr $h1 /* 60 +... (8 Replies)
Discussion started by: abhishek27
8 Replies

9. Shell Programming and Scripting

How to debug the awk script

Hi, How can I debug an awk script? I know that set -x can be used to debug a script. But this will not suite for awk scripts. Can anyone help me? Thanks in advance, Chella (2 Replies)
Discussion started by: chella
2 Replies

10. Shell Programming and Scripting

Debug an Awk Script

I would like to extract the following fields from the text file attached. I copied the contents from a pdf file and pasted them into the text file so I can use awk to extract them. The layout is as listed below. name1,name2,name3,name4,Title,designation,nationality,dob, national ... (1 Reply)
Discussion started by: mboro
1 Replies

Featured Tech Videos