For whatever reason, my external harddrive pretty regularly experiences initramfs issues on boot, causing me to run $ fsck /dev/sdb2 -y to bring everything back in line.

One thing I have noticed though, is that shutting down or restarting the system with the titled command greatly reduces the occurrence of this error.

Is there any way to create a script or terminal alias that would "go through the motions" of pressing those keys (with a small delay between each letter)? So rather than play digital gymnastics with my fingers and toes, I could simply type $ reisuo and it would go through the motions for me?

  • After this has sent TERM and KILL signals to all processes, how do you expect the rest of such a script to continue running?
    – JdeBP
    May 6, 2019 at 22:20
  • Hello @JdeBP! You raise a very good point. Are you saying, then, that perhaps this type of command "must" be manually typed out for that reason?
    – Spectator6
    May 7, 2019 at 14:40

2 Answers 2


for c in r s u o; do
  echo $c > /proc/sysrq-trigger
  sleep 1

(Though, the CTRL key is not simulated, and it has no effect anyway)

Edit: removed e i since they kill processes, including current shell and the rest of the script would not continue. You would be better off using kill or slay anyway. And when you are doing SysRQ s u o, r is irrelevant.

  • Thank you @Radovan! What would I need to research to learn what is being programmed here? Is this a type of shell programming or something?
    – Spectator6
    May 6, 2019 at 19:34
  • 1
    Yes it is shell programming. The for loop makes the variable called c take each of the values in turn. The echo $c outputs the value of the c variable to the special sysrq-trigger file provided by the kernel to trigger the same routines that the keyboard sequences do. The sleep 1 makes the program pause for (at least, but usually not significantly more than) one second. The do and done delimit the command to be done for each value of the variable c.
    – icarus
    May 6, 2019 at 19:45
  • @icarus Whenever I try to the run the above script, I receive the following notice "cannot create /proc/sysrq-trigger: Permission denied". Running ls -lh on the file returns -rwx------ linux root. "linux" is the name of my current login... Any ideas how to get around this?
    – Spectator6
    May 6, 2019 at 20:54
  • It would seem a lot simpler to just use the sync and umount/mount commands.
    – JdeBP
    May 6, 2019 at 22:21
  • Instead of using reisuo to run the script, use sudo reisuo to run it. It should also be possible to alter the udev rules to change the permissions on the file.
    – icarus
    May 7, 2019 at 6:36

For those like me who may be new to shell scripting, here's a step-by-step for how I was able to get @Radovan's script up and running:

  1. $ cd /usr/local/bin This is where the scripts will be saved. Saving scripts in this directory does NOT require adding new PATHS.
  2. sudo vim rsuo.sh To properly interact with this directory, the script will need to be created with sudo privileges
  3. Add @Radovan's script above which, thanks to @JdeBP's great advice, now omits the the SIGTERM and SIGKILL commands so the script is able to run to completion
  4. After saving the file, its permissions need to be expanded so the non-root user can access it, with the following commands: $ sudo chmod u+x rsuo.sh and/or $ sudo chown <user_name> rsuo.sh
  5. Now that the file is all set, to create an alias for the command, open the .bashrc ($ vim ~/.bashrc) and add alias rsuo="cd /usr/local/bin && sudo rsuo.sh"
  6. Once that's saved, close and restart your terminal, and when you type $ rsuo, it will prompt you for your sudo password, then execute the script.
  7. I repeated the above steps for the rsub command, that way I can also have a way to reboot the system.
  8. Consume Double Stuf Oreos to your liking ;)
  • In step 4, the chmod is mandatory and the chown is unnecessary.  If /usr/local/bin is in your PATH (as stated in step 1), then you don’t need to do cd /usr/local/bin in step 5. May 10, 2019 at 1:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .