Run script at shutdown linux

service's final version: Feb 06, 2018 · The best way to run scripts and commands on suspend and resume on Linux before suspending (or after resuming) is to use the systemd init system. local script is executed by the init command at boot time or when changing runlevels. biz 'sudo shutdown -h now ' Q: I would like to run a script at system shutdown, how do I do that? A: The best way to do so, is to add it to the /etc/init. 1 and Note 1397813. local. sh. local before the desktop environment such as GNOME or KDE is The script /etc/rc. However, to run it, in some cases, you need to have root privileges. Is there is an easy way to run script or command at boot time after fresh reboot command? How can I  I am trying to log uptime on shutdown and reboot with no success. d/halt /etc/init. New to Debian (Or Linux in general)? Ask your questions here! 10 posts • Page 1 of 1  24 May 2018 This can be done automatically by defining commands or scripts in certain files in Suse Linux. The shutdown command is used to halt/shutdown, reboot the Linux Operating System. 1 Common Errors Access to the root account This method uses sudo to allow a user to run shutdown as root. To run a script or command before server initiate shutdown, you need to specify them in /etc/init. Dec 21, 2015 · Learn to shut down or reboot your Linux system, warn users that the system is going down, and switch to a more or less restrictive runlevel. biz 'sudo halt' OR use the shutdown command: ssh -t vivek@server1. You can run the script at reboot or shutdown using cronjob and for that you need to write the following line in the cronjob. In order to reboot the system immediately, we run: sudo shutdown -r now The '-r' option specifies the command to reboot instead of powering it off. If you want to 'force close' running applications on a shutdown, type “/S /F”. Linux Shell Script Examples Linux specifics. May 14, 2018 · Here is a very simple linux bash script to shut down all VMs of a ESXi host and the host itself, for example when a power failure occurs, this script can be used in UPS software. The script is run-able in a vMA (vSphere Management Assistant). d/start script Nov 06, 2020 · The simplest Linux terminal command to power down a system is 'shutdown' command and it should work on Ubuntu and Centos/RHEL machines. So for this, I kept this script into /etc/init. sh before Systemd stops the libvirt-guests service. rsync -vahz --delete /home/<user>/eMail/ <user>@server:eMail/ rsync -vahz --delete /home/<user>/Profiles/ <user>@server:Profiles/. d and /etc/rc. d, then put a symlink in /etc/rc0. So you're if you're not seeing the email from the shutdown, then try adding a "sleep" instruction to the "stop" function, so the server gets an opportunity to send the email before all the other services are stopped May 12, 2017 · For instance, the shutdown command will also write a shutdown script. Red Hat Enterprise Linux 7  4 May 2019 Linux shutdown command help and information, with shutdown and decide not to run fsck since the system has been shut down in the proper  12 Dec 2018 I want to run a Bash script prior to either shutdown or reboot of my Pi (running the latest Raspbian). exe --shutdown does not give Linux time to stop services, in journalctl it looks like the worst kind of shutdown, it just gets blank. Make it executable: sudo chmod +x K99_script. All of that is great, but what if you're running a distribution of Linux that uses systemd instead of SysVinit? Turns out, it's much simpler with systemd. Linux is powered/halted at the specified time. Adding commands to the bottom of this script is an easy way to perform necessary tasks like starting special services or initialize devices without writing complex initialization scripts in the /etc/rc Jan 03, 2019 · Method 1 – Using rc. Executing Linux Scripts During Reboot or Startup There are two traditional methods to execute a command or run scripts during startup: Method #1 – Use a cron Job Besides the usual format (minute / hour / day of month / month / day of week) that is widely used to indicate a schedule, cron scheduler also allows the use of @reboot. Make script executable and Enable to run on boot. g. I created. If you want to shut down the computer immediately, you can use this command::~$ sudo shutdown now Aug 22, 2016 · This tutorial will help you to run scripts on system startup and shutdown on Gentoo Linux. Apr 13, 2018 · Run Script Before Shutdown with VMware Tools Apr 13, 2018 / Karim Elatov / vim-cmd , vmware-tools As a continuation of my efforts from my previous post about VirtualBox with VMware, I wanted the VM to be part of auto power on and off process. This tutorial will help you to run scripts on system startup  I have a backup script that I have setup to run on command, but I would rather that it ran automatically. This script is run before any other actions are taken Run scripts in Azure virtual machines. local file but it would not activate the script. Linux will only run your stop script if it can determine that the "subsystem" is Sep 27, 2000 · The /etc/rc. shutdown)" /etc/rc. allow. d/start. As the name suggests, shutdown command can be used for managing the state of the system, that is, powering-off or rebooting. Login as root Add user to Jan 25, 2021 · Shutdown scripts function very similarly to startup scripts. The basic usage is easy - all you have to do is to run the 'shutdown' command. On Ubuntu, scripts for the different runlevels are executed according to  How to run script with systemd right before shutdown in Linux · Step 1: Overview on systemd · Step 2: Create Sample Script · Step 3: Create unit file to run script with  7 Nov 2011 Execute script before shutting down in Ubuntu · linux ubuntu ubuntu-10. Script can be typed directly or you can run one of the built-in scripts. In runit, these scripts are called by /etc/runit/3. We will make an entry to execute the script in the file & every time when our system starts, the script will be executed. service: [Unit] Description=/etc/rc  20 Feb 2016 [SOLVED Run script/command before shutdown/reboot. 25 Jul 2020 How to run a shell script at system startup and shutdown Good idea to create a /etc/rc. Much of the documentation for startup scripts also applies for shutdown scripts. S stands for start scripts, thus they are run when system starts, K stands for kill scripts, thus they are run when system is shut down. at> <EOT>. This is a lot easier than making each script you want to run an init script. Moreover, a modest knowledge over this topic will make you a Linux power user in no time. Feb 27, 2013 · I need a script for shutdown the system automatically if the system is not disturbed for last 10 minutes. Then, create a symlink under /etc/rc0. Setting shutdown scripts to run synchronously may cause the shutdown process to run slowly. systemd. Typical vanilla /etc/init. /K99sendir it works but it does not work when I actually shutdown the system. I am able to invoke the script via terminal successfully. Jan 27, 2021 · I am going to use this one line shell script to make things as uncomplicated as possible: [email protected]:~/Scripts$ cat hello. Code: Aug 19, 2015 · In this tutorial, we will see how to easily run or start a bash script at startup, reboot, or shutdown under Ubuntu or any of its derivatives (Linux Mint). For the We will perform a shutdown of my CentOS/RHEL 7/8 Linux node to check if it run script with systemd at shutdown only and not at reboot. I want some of my files/folders at linux partition to be copied to my ntfs partition whenever I shutdown my Ubuntu Desktop. but  25 Sep 2016 Linux Mint is based on Ubuntu, so I'm guesing the runlevel system is probably the same. after. If I look in the group policy logs in event viewer when it doesn't run there is nothing in the group policy log at the time of shutdown (surely there should be something even if there was a problem with the script) Aug 07, 2017 · OR use the shutdown command: ssh -t vivek@server1. – NarūnasK Mar 10 '17 at 21:45 I created a script for that and this will run once in a day and now I want that it will run when the server is going to reboot or shutdown. @reboot /bin/bash /root/test. 29 Nov 2012 I have not been able to use it in Lion or Mountain Lion. I can get the script to write a text file log that it completed successfully to the user desktop on shutdown and reboot and even make a local copy. target'. target' for 'multi-user. Follow the steps below to make script executable and enable to run automatically when system boots up. Apr 22, 2017 · qshutdown is yet another utility to auto shutdown, reboot, suspend, and hibernate your system at a specific time. May 06, 2014 · This script may be a good starting point for creating your own init script to perform needed pre-shutdown actions, but keep in mind that we still have a 5 minute window to cleanly shut down our VM before it is powered off. d/halt. But no idea how to do so. d Make it executable: sudo chmod +x K99_script put my script (name: sendir) in /etc/init. PowerOff Scipts; VMware Tools Logging; Sending a Guest Shutdown Command from an ESXi  I know the possibility in snow leopard to execute a script during system boot by using a launchd script located in I tried a rc. You cannot, for example, have the dbstart script automatically start sid1, sid2, and sid3, and have the dbshut script shut down only sid1. When shutdown is entered correctly—as root, and with a valid time argument — it does the following. Modern Linux will first boot into systemd while older versions of Linux uses System V init. Since these are gigabytes the script will take several seconds, so the shutdown  run script at shutdown linux d pointing to the script to run it at run level 0. After the shutdown command is issued, the system will send a notification to all logged-in users and process indicating that the machine is going down. local script in order to start your appls. On shutdown or reboot, the system runs the scripts in /etc/rc0. d/rc3. 04 gnome shutdown. Just got the Like the K-scripts in Linux. d via . local’ file located in ‘/etc/’ to execute our scripts and commands at startup. stop will be executed during system shutdown. Write a script and put it into /etc/init. 04 Desktop, side by side, with Windows XP (Dual Boot). and to halt enter /sbin Oct 01, 2019 · On the recent Linux distributions shutdown is an alias to systemctl and it is available in the system only for compatibility reasons. The simple sudo apt-get install samba-common command will do it for any Debian-based Linux. I use the script frequently on Windows and Linux and have installed it on a Mac. Your S and K scripts in /etc/init. That's why the script has to be placed in ExecStop=. Then I created symbolic links to rc0. . that the following procedures are applicable to Red Hat Enterprise Linux 4/5/6 distributions. That is, you must have superuser permissions and be able to use the sudo  27 May 2019 The shutdown command in Linux is used to shutdown the system in a safe way. Often it is useful to grant non-super users the ability to shutdown the server. For Software and Web Development. 1 Nov 2016 Linux and Unix systems have long made it pretty easy to run a command on boot. d/my_maintenance. Sep 28, 2019 · The graceful-shutdown service will cause Systemd to run a Linux shell script, /sbin/stoplab. Some time ago a posted how to use such script in an HPE UPS environment. 1 Requirements 2 Method 1 (recommended) 3 Method 2 3. You can To display shutdown details run below command. A value of zero indicates At any of the startup stages you can set your own autostart script or program; it could be a single command, a chain of commands or an executable shell script. Adding commands to the bottom of this script is an easy way to perform necessary tasks like starting special services or initialize devices without writing complex initialization scripts in the /etc/rc Apr 26, 2007 · There is a "backup-script" I want to run before windows shuts down. Similar to the rebooting script, the name of your rebooting script must begin with K99 in May 24, 2018 · So it was a successful run. This is what the script looks like: #!/bin/bash irsend SEND_ONCE ph_remote KEY_POWER First create the scripts you want to run at startup and/or shutdown. 2 Grid Infrastructure), the startup/shutdown script may no longer be used. if I type in sudo shutdown now or sudo  22 Aug 2016 This is helpful for starting a service on system start and stop it during system shutdown. Step 3: Use Kill Command Options to Terminate a Process There are a few different methods of killing a process in Linux, depending on whether you know the name of the process running, the pid of the process, or just how long the process has been running. I'm pretty new to linux, after like 3 weeks of using it, did some updates here and  28 Sep 2018 where the server runs rsync and is connected via ssh/public key. As per Note:105957. 6 is the rebooting script for the traditional init, while /etc/rc. By the way i am using RHEL 4 in my system. shutdown. This is due to the fact that the init system interacts directly with the kernel, and power systems. d and make it executable through sudo chmod +x myscript. You want more information about the same topic so you can reach to my blog  I also asked for help in Arch Linux Forums and with help of MK13 user it was possible to solve this problem:  If you want to stop bash script, that is currently running, you can do following sentence in bash: kill $(ps aux | grep name_of_scirpt | grep -v grep | awk '{ print $2 }'  This command allows the task to start a basic shutdown. Can be run using Azure portal, REST API, Azure CLI, or PowerShell; Quickly run a script and view output and repeat as needed in the Azure portal. To reboot you enter /sbin/runit-init 6. d. The script would typically go into /etc/init. See full list on howtogeek. How to run script with systemd right before shutdown in Linux Step 1: Overview on systemd I hope you are already familiar with below topics Overview on systemd and how it is Step 2: Create Sample Script Now to run script with systemd right before shutdown we need a script or command. Running Additional Programs at Boot Time The /etc/rc. sh where /root/test. Mar 13, 2019 · I tried the same and the script didn't run. d/rc if it does exist. Run PowerShell script in Windows machines and Bash script in Linux machines. service waits for 5 minutes for each such VM and then destroys it. d $ mkdir -p /etc/init. exe sudo systemctl stop srv && wsl. Aug 07, 2017 · How to shutdown the remote Linux server. For the bash scrip to run properly, make sure it is executable and well-coded. Now create the /etc/init. Run script or command before server shutdown. Now you can reboot a machine remotely with the following syntax, making sure to use a username that has Hello, I have a backup script that runs an rsync backup to an external drive. In order to avoid that and shut them down cleanly, I have created custom VM shutdown service, with a script that uses special methods to shut them down: Jan 11, 2021 · The easiest way to run . description "my shutdown script" start on desktop- end task console log script exec ~/scripts/backup. Standard permissions do not allow regular users to shutdown a unix machine. there are a number of ways to do this. Apr 25, 2019 · Shutdown in Linux. 10 on my family's PC uses systemd. From cmd I can do wsl. 1. The first case starts the listener/DB whereas the 2nd case stops it. Scripts within this directory starting with a K are kill scripts and are run first. d/reboot /etc/shutdown. 2. Apr 12, 2019 · Also returns PIDs of shells that are running scripts. Jul 07, 2020 · Note that the scripts in this directory will be executed in alphabetical order. After going over the linux script /etc/rc. d instead of rc6. d should run as you would expect. To execute a script at shutdown or reboot: save your script in /etc/rc6. d directory and created a symbolic link in /etc/rc6 and /etc/rc0 directory. e. The command that allows you to shut down a Linux system is the shutdown command. Both method will run cron and rc. conf . This will be useful to run your favorite program or scripts automatically without starting them manually. Runlevel 0 is entered when halting the system. d directory and link it to rc0 and rc6 (reboot and shutdown). Thus the first thing that needs to be verified when a script is not being run properly by PowerChute Network Shutdown is that the script is written for the Bourne Shell. Click "OK" when finished. 2 ASM or CRS managed database (using the 11. Please have a look and help in these regards. 25 Jun 2014 Windows, Apple and Linux IT support and services. sh is the script. Please note  23 Oct 2017 I was rushing to leave and was still logged into a server so I wanted to shutdown my laptop, but what I didn't notice is that I was still connected  24 Oct 2018 Issue: How to run and troubleshoot scripts / command files with PowerChute Network Shutdown on Unix/Linux Product Line: PowerChute  Linux Mint는 Ubuntu를 기반으로하므로 실행 수준 시스템이 동일하다고 생각 합니다. sysinit script When a Linux system is booted, the kernel runs init, which in turn runs the /etc/rc. d as Knn and Snn for Kill and Start, where nn is a number that determines the sequence during startup / shutdown the script is run. When starting gnome it runs the script and copies the files just fine. cyberciti. Startup and Shutdown Scripts. You can use the material in this article to study for the LPIC-1: Linux Server Professional Certification, or just to learn about shutting down, rebooting, and changing runlevels. d (shutdown) and rc6. target I don't give up. I create the file /usr/lib/systemd/system/uptime. Run a script  19 Jul 2019 I am on Red Hat Enterprise Linux server. Any expert pls help. sh Scripts that are to be run by PowerChute Network Shutdown need to be written in the Bourne Shell and should start with a line that resembles the line above. d/ created a symbolic link to it in /etc/rc6. Use the crontab -e command to open your user account’s crontab file. Then make sure that they are both executable by right clicking the file, selecting properties and making sure that, under permissions, you have ticked Allow executing file as a program. What I would like to do is run a script (ArchBoxBaksScript. The shutdown accepts -h option i. d pointing to the script to run it at run level 0. d/rc. scfullcopy_atend. Nov 23, 2018 · Still the script can be configured to handle starting up and shutting down iAS processes. d scripts using below steps. So, I altered the Install section and I changed 'shutdown. The following solution is working for me: [Unit] Description= [Service] Type=oneshot RemainAfterExit=true ExecStop=<your script/program> [Install] WantedBy=multi-user. In  28 May 2019 To run any of these commands you have to be in the sudo group. On logout I am not having any success. But just like Linux itself, there may be no one-size-fits-all approach here for all distributions and workloads. d, and have a link in /etc/rc. The shutdown script that calls halt as the last thing in the shutdown sequence should check these environment variables and call halt with the right options for these options to actually have any effect. When I shut down my computer I want to show some pending tasks  7 Jul 2020 Note: Scripts are run in the alphabetical order in directories, and all scripts should be named following Linux's nomenclature rules. First make sure you have enabled local. Let’s start at the beginning. How to Use the shutdown Command # Only the root and users with sudo privileges can use crontab command. The first method involves passing the script file name as an argument to the shell. Additionally, if you want to run something before any of the runlevels start, you can put it in Oct 05, 2018 · Your script doesn't have any "daemon" or "background" processes in it that would continue to run after the script terminates. where the server runs rsync and is connected via ssh/public key. sh) on shutdown (not needed on reboot). shutdown ES=$? 5 Dec 2012 In this tutorial we learn linux shutdown command with some practical examples. sh file shell script on Linux is as follows: Set execute permission on your script: chmod +x script-name-here. In this method, we will use ‘rc. job 48 at Fri Jul 21 15:32:00 2017 . The script has an option to run shutdown after the backup has completed. d. Open the terminal (your shell prompt) and type the commands. 14 Aug 2016 If you want run script on shutdown then use rc0. com Dec 06, 2019 · Hi, We have a shutdown script setup on our win 10 machines (mixture of 1511 and 1607) However the script does not run on every shutdown. e. How do I run . I have read that I can use the group policy editor, and put the batch -or- VBS file in with the shutdown scripts, but I am May 27, 2010 · $ mkdir -p /etc/init. d/ directory. sh file shell script in Linux? The procedure to run the . So its operation is quite simple. I have the following script, how do I run it on shutdown in debian linux? (don't want to use GUI) #!/bin/bash vms=$ (vmrun list | grep '/'); for vm in $ {vms} do echo 'suspending ' $vm vmrun suspend $vm soft done I tried adding it to /usr/local/bin with chmod +x permissions. d/rc0. The default behavior of this tool is to power off the machine. d/ directory with suffix . STEP 5 We will now create a wrapper script that can be used to schedule as a service. For both shutdown and reboot tasks, VMs always run shutdown scripts as follows: For Linux VMs, by using the root user. For Windows VMs, by using the System account. d You put scripts you want to run during boot in start. As it happens on Debian 9. How To Execute a Script at Shutdown In order to execute a script at shutdown, you must put your script in /etc/rc6. Also I would recommend to create Systemd unit files (if you are using new version of Ubuntu) rather than SysV scripts. 20 Sep 2016 only at shutdown/reboot time? How to run a service script right before shutdown in RHEL 7? Environment. So everything has to be thought reverse, dependencies too. The name of your script must begin with K99 to run at the right time. local script will run before any of the run level shutdown scripting starts. Files /fastboot /etc/inittab /etc/init. start is called at reboot or system startup and stop is called at shutdown. Perhaps, you just want to do low-level maintenance, halt will be a suitable command to use as it will stop all running process and stop the CPU as well. That&#39;s why ec2-reboot sometimes doesn&#39;t work if the instance has run out of memory. You can find the post here. Note that the shutdown command provided by sysvinit package will not work in runit. Stay with us to for a detailed introduction to Unix shell scripting. at> ls -l >> test. biz 'sudo shutdown -h 0' OR ssh -t vivek@server1. Distribution: Linux Mint 17. [root@centos-8 ~]# shutdown now After the node comes UP we check the content of our /tmp/file where we were writing our content from the dummy script Try renaming your script to K99testscript. Nov 01, 2016 · After putting that script in /etc/init. So they operate as if /sbin/shutdown was called with -h or -r respectively. Using the shutdown command. Here it is the uptime. d/rc sysinit script. Notifies all users the system is going down; Blocks additional logins; Notifies all running programs so they can close/save files and exit gracefully Creating simple yet effective Linux shell scripts for tackling day to day jobs is quite easy. To install it on Ubuntu and its derivatives, run the following commands one bey one in your Terminal: Auto Shutdown Server. Examples shutdown 8:00. The syntax is: ssh user@server-name-here Type the following command to reboot the box: sudo halt Another option is: ssh -t vivek@server1. Now the scripts inside /etc/local. local doesn’t exist by default, but it will get executed by /etc/init. I have had to configure both  29 Jan 2019 I am trying to get a bash script to run at shutdown/restart. So, we need to create a script under /etc/init. Jul 14, 2018 · Updates to WSL have included adding support for background tasks when all your Linux console windows are closed, where previously the WSL processes had to be running under a live shell. The first solution I found was to place the script in /etc/init. The scripts refer to the same entries in the oratab file, which are applied on the same set of databases. Rest of the script is pretty easy to understand. Here's a sample script: For the sake of this exercise, let's call it: shutdown_job #! /bin/sh ### BEGIN INIT INFO # Provides: shutdown_job Jul 27, 2020 · The command wsl. 1, When using an 11. Only then will  Run script on shutdown linux. Hi, ec2-terminate, like ec2-reboot, triggers /sbin/shutdown to manage the process. Because the shutdown order is the reverse startup order. Scripts that are to be run by PowerChute Network Shutdown need to be written in the Bourne Shell and should start with a line that resembles the line above. d . This is one. 9 Jan 2021 In this post we will see how to pause (suspend) and start a linux process using signals (SIGTSTP and SIGCONT) via kill command. start will be executed at system startup and all the scripts with suffix . d (reboot). You can Only root user can execute shutdown command. As covered in the section on starting up, when Linux enters a given runlevel, the init process executes the scripts found in /etc/rc#. If you use PsShutdown utility to execute shutdown operation, you can let it run at To execute shutdown of the remote PC at 21:00 type a following command in  2017년 7월 21일 warning: commands will be executed using /bin/sh. Local Group Policy Editor and the Resultant Set of Policy snap-in are available in Windows Server 2008 R2 and Windows 7 Professional, Windows 7 Ultimate, and Windows 7 Enterprise. Aug 25, 2009 · Hello all, I have been using Ubuntu 9. scopening_atstart and. Dear All I want to achieve the following task . Your script must have start or stop options or both, depends on when you want to run your script. Because the service type is oneshot, Systemd will wait until the script exits before it continues with its standard shutdown process. d and scripts you want to run at shutdown in stop. d and give executable permission. biz 'sudo shutdown -h now ' You must pass the -t option to the ssh command to force pseudo-terminal allocation. Feb 13, 2018 · By default, the run level while system shutdown is 0. Since backup can take hours to run, this is an option that is (10 Replies) Jul 10, 2017 · First, open a terminal window from your Linux desktop’s applications menu. In AIX, startup of How to Determine a Linux Login from a User Vs a Process/Remote Ex 24 Dec 2020 Since rebooting or shutting down a system will stop all running processes, we need to have root permission to execute those commands. M. It works well on Ubuntu, Linux Mint and other Ubuntu variants such as Kubuntu, Xubuntu, Lubuntu, etc. You can click the Dash icon, type Terminal and press Enter to open one if you’re using Ubuntu. sh start end script. Linux Forums on Bytes. 0 (symlinked to the former) is the halting script. Sep 28, 2018 · Code: Select all. Considering that bash is the May 27, 2010 · the halt. Linux and Unix  13 Jan 2018 Gentoo Linux on my laptops uses OpenRC with SysVinit, whereas Lubuntu 17. Please note that the scripts in this directory are executed in alphabetical order. Commands in this file run with your user account’s permissions. 5 host, on shutdown the libvirt-guests. sh shell script in Linux or UNIX is to type the following commands. Schedule the system to shut down at 8 A. shutdown. local looks like below – Mar 10, 2009 · 1. It then runs all of the start scripts (their file names start with an S) in the appropriate run level directory so that all services and applications are started correctly. d/rc, I found that linux (in its infinite wisdom) decided to add an additional "feature" to the start/stop scripts. "Running local shutdown scripts (/etc/rc. exe sudo systemctl poweroff but I’m trying to automate this behavior. However, you still needed to start those services yourself because Linux sessions could only be initiated explicitly. 1 I could do this at startup or on a 'cron' or 'at' command, but I would rather 5 Jul 2016 In theory you can use the old SysVinit approach but my shutdown scripts were not executing so I decided to bite the bullet and learn how to do it  config/upstart/shutdown. You will probably remember halt quicker than Shutdown -H and as for reboot, self explanatory. d/stop. But as it turns out, running a command on shutdown is a little  4 The method in the link is valid and works on all linux version so your script is wrong ;) · Does it work? · @user2135804 I thought it did. Thankfully even if you restart or shutdown using the Apple menu the UNIX commands are  i want to run a script when the user clicks the shutdown button in kde if i I have been using Linux for a while, but I have never had to modify it's  13 Apr 2018 Run Command on Poweroff with VMware Tools. Execute command before shutdown/reboot, in /etc/ rc6. Since these are gigabytes the script will take several seconds, so the shutdown must wait for it to complete before closing the network or unmounting the disks. Application auto start-stop along with OS reboot. d with the name K99sendir; The script is executable and if I run it inside /etc/rc6. sh echo "Hello World!" Method 1: Running a shell script by passing the file as argument to shell. I noticed that my shutdown scripts were NOT being executed on Linux at system shutdown. d/runmycommandatshutdown and enabling it with chkconfig on runmycommandatshutdown, your command will be run at shutdown.