Sponsored Content
Operating Systems Linux Red Hat Where to put script to be executed before shutdown ? Post 302998269 by Aia on Sunday 28th of May 2017 09:11:39 PM
Old 05-28-2017
Write a service file and place it in /etc/systemd/system/beforeshuttingdown.service
Code:
[Unit]
Description=Before Shutting Down

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=<path to script or program>

[Install]
WantedBy=multi-user.target

Your program or script must be executable.
Code:
systemctl daemon-reload
systemctl enable beforeshuttingdown.service
systemctl start beforeshuttingdown.service


Last edited by Aia; 05-28-2017 at 10:41 PM..
This User Gave Thanks to Aia For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to know who executed a script?

Dear all I would like to capture who executed a script to a script's variable (i.e. testing.sh), so I can save it to a log file. testing.sh #! bin/ksh user=`<< code here >>` // get the info below in RED color <<main logic>> echo "$user execute testing.sh on `date`" >> testing.log ... (2 Replies)
Discussion started by: on9west
2 Replies

2. UNIX for Dummies Questions & Answers

Script to force Oracle database shutdown when shutdown immediate does not work

I have Oracle 9i R2 on AIX 5.2. My Database is running in shared server mode (MTS). Sometimes when I shutdown the database it shutsdown cleanly in 4-5 mints and sometimes it takes good 15-20 minutes and then I get some ora-600 errors and only way to shutdown is by opening another session and... (7 Replies)
Discussion started by: aixhp
7 Replies

3. Shell Programming and Scripting

Variables of executed script available in executing script

Hi, I have a script get_DB_var.ksh which do a data base call and get some variables as below: sqlplus -silent $user/$pass@dbname <<END select col1, col2, col3 from table_name where col4=$1; exit; END Now I want to access all these variables i.e.... (9 Replies)
Discussion started by: dips_ag
9 Replies

4. AIX

Script not getting executed via cron but executes when executed manually.

Hi Script not getting executed via cron but executes successfully when executed manually. Please assist cbspsap01(appuser) /app/scripts > cat restart.sh #!/bin/ksh cd /app/bin date >>logfile.out echo "Restart has been started....." >>logfile.out date >>logfile.out initfnsw -y restart... (3 Replies)
Discussion started by: samsungsamsung
3 Replies

5. Shell Programming and Scripting

script has been executed successfully or not??

Guys, How can we know whether a script has been executed successfully or not ? We dont have any log directories, and we are not given a chance to modify the script. Could someone help me out with this Thanks (2 Replies)
Discussion started by: bobby1015
2 Replies

6. Shell Programming and Scripting

Shell script executed from Informatica ETL tool is spawning 2 processes for one script

Hi, I am having a shell script which has a while loop as shown below. while do sleep 60 done I am executing this script from Informatica ETL tool command task from where we can execute UNIX commands/scripts. When i do that, i am seeing 2 processes getting started for one script... (2 Replies)
Discussion started by: chekusi
2 Replies

7. Shell Programming and Scripting

Shell script not getting executed

Hi As per my requirement when I run . ./file.sh am getting the following error -bash:ELF: command not found when i execute as ./file.sh it is getting executed.How to resolve this. Thanks in advance. (3 Replies)
Discussion started by: pracheth
3 Replies

8. Shell Programming and Scripting

INIT Script Getting Executed Twice?

Hello All, I copied and pasted the "/etc/init.d/skeleton" file to a new one so I could create my own init script for a program. Basically the ONLY edit I made to the skeleton "template" so far was to search and replace "FOO" with "snort". *NOTE: I know there are a bunch of snort init scripts... (6 Replies)
Discussion started by: mrm5102
6 Replies

9. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

10. Shell Programming and Scripting

Script is not getting executed

Hi All, I have written a programme where i need to work in one session but when that session get executed it doesnt execute other programme till I write exit. Below is the script #!/bin/bash echo 'Going to start' exectrusteduser.com sh.com cd /UAT_Logs/CDCI_LOGS/SEEDADM pwd echo... (6 Replies)
Discussion started by: ripudaman.singh
6 Replies
reboot(8)						      System Manager's Manual							 reboot(8)

NAME
reboot, halt, poweroff - reboot or stop the system SYNOPSIS
reboot [OPTION]... halt [OPTION]... poweroff [OPTION]... DESCRIPTION
These programs allow a system administrator to reboot, halt or poweroff the system. When called with --force or when in runlevel 0 or 6, this tool invokes the reboot(2) system call itself and directly reboots the system. Otherwise this simply invokes the shutdown(8) tool with the appropriate arguments. Before invoking reboot(2), a shutdown time record is first written to /var/log/wtmp OPTIONS
-f, --force Does not invoke shutdown(8) and instead performs the actual action you would expect from the name. -p, --poweroff Instructs the halt command to instead behave as poweroff. -w, --wtmp-only Does not call shutdown(8) or the reboot(2) system call and instead only writes the shutdown record to /var/log/wtmp --verbose Outputs slightly more verbose messages when rebooting, useful for debugging problems with shutdown. ENVIRONMENT
RUNLEVEL reboot will read the current runlevel from this environment variable if set in preference to reading from /var/run/utmp FILES
/var/run/utmp Where the current runlevel will be read from; this file will also be updated with the runlevel record being replaced by a shutdown time record. /var/log/wtmp A new runlevel record for the shutdown time will be appended to this file. AUTHOR
Written by Scott James Remnant <scott@netsplit.com> REPORTING BUGS
Report bugs at <https://launchpad.net/upstart/+bugs> COPYRIGHT
Copyright (C) 2009 Canonical Ltd. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
shutdown(8) telinit(8) runlevel(8) Upstart 2009-07-09 reboot(8)
All times are GMT -4. The time now is 07:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy