Run a script via Alias Command - CentOS & Red HAT

Its possible to run a script via Alias command. All you need is to modify the .bashrc and then source the script in the required user profile. Alias commands are very useful when it comes to running shortened versions of commands or a complex script to be run using just a single line of command. Currently I use this to run 2 of my custom scripts for waking up a ESXi server via WOL (Wake-ON-LAN).

All you need to do this first create (or) select a script you want to run as an Alias Command.

I have got 2 scripts located in /home/pi/

  • hppl-1-vh.sh
  • hppl-2-vh.sh

Now go ahead and edit the .bashrc file for a user who wants to run the command. In this case the user is 'pi' and file is "/home/pi/.bashrc".

Edit "/home/pi/.bashrc"

# vi /home/pi/.bashrc

Add the above 2 scripts to the end of the file so that they can be called by the command "wakie-esxi"

alias wakie-esxi='source /home/pi/hppl-1-vh.sh && /home/pi/hppl-2-vh.sh'

And then you can either log-off and login back for the changes to take effect (or) if you want to apply the changes on the fly without logging off then run this command as given below.

# source /home/pi/.bashrc

And that should be it and you should be able to call scripts via Alias commands.

Output: 

pi@rasst ~ $ wakie-esxi
hppl-1 is UP as on Mon Feb  8 09:36:16 GMT 2016
hppl-2 is UP as on Mon Feb  8 09:36:17 GMT 2016

If any issues please let us know via Contact Us and we will try our best to help you out.

Most Read Articles

Add/Detect a new disk in ...

Written By Farooq Mohammed Ahmed on Sunday, 11 January 2015 19:22
Add/Detect a new disk in ...

Replace SSL Certificates ...

Written By Farooq Mohammed Ahmed on Friday, 16 December 2016 08:05
Replace SSL Certificates ...

Using awk in Alias Comman...

Written By Farooq Mohammed Ahmed on Friday, 19 February 2016 14:22
Using awk in Alias Comman...

Script to Monitor Nagios ...

Written By Farooq Mohammed Ahmed on Monday, 18 July 2016 22:48
Script to Monitor Nagios ...

Generate/Create a SHA2/SH...

Written By Farooq Mohammed Ahmed on Tuesday, 25 October 2016 13:56
Generate/Create a SHA2/SH...