Short cut for invoking shell script in unix - unix

I have below two file to start and stop my spring-boot application. Is it possible to have this installed as server etc in unix? so that I can just type start app or stop app to start or stop my application from any location?
startApplication.sh
stopApplication.sh

You can always define alias in your bash, do as below:
sudo vim ~/.bashrc
go at the end of file and add this line
alias start-app='bash /<path-to-script>/startApplications.sh'
save and exit and resource it with source command
source ~/.bashrc
now if you type in your terminal start-app it will execute your script. create one for stop-app too.

Related

Added Alias to .bashrc but no results

I added an alias (alias homedir='cd /export/home/file/myNmae'
) to .bashrc in my home directory and restarted the session. When I run the alias it says homedir: command not found.
Please advice.
This is because .bashrc is not sourced everytime, only for interactive non login shells .bashrc is sourced.
From the bash man page.
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/pro-
file, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the
first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.
When a login shell exits, bash reads and executes commands from the files ~/.bash_logout and /etc/bash.bash_logout, if the files exists.
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the
--norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.
i found the solution - i added it to the .profile file and restarted the session - it worked

Is it possible to add custom commands to tmux?

I have some commands in mind that I don't want to create keybinds for and would prefer to use command mode for them. For example, I want something like:
<C-a>:restart-guard
That I can have run a script to run some commands in my guard window
Is this possible?
You can't define user defined commands directly
But you can always call a tmux script with so (shortest alias of source-file) or a program with ru (shortest alias of run-shell)
For so, you need to give the path to the command or to have the tmux server to start in the folder where your custom commands are
Here is a simple example, you put your restart-guard script in ~/.tmux/commands
you start tmux using a scipt :
#!/bin/bash
cd ~/.tmux/commands
tmux
then inside tmux, do
<C-a>:so restart-guard
I am currently looking for a way to have the directory where you started tmux and not the ~/.tmux/commands directory when starting
That is unfortunately not possible with tmux at this moment.

Autosys: Change directory before executing job

I'm new to Autosys and I'm using the WCC front end in order to run autosys jobs. I also have access to the terminal if the answer proves to only work in the terminal
I was wondering how to change the directory before running a job. At the moment, Autosys searches its root directory for a batch file buit I want it to point to C:/scripts. IS there any way to define this as the starting directory or am i stuck leaving script files in the root directory of Autosys?
Thank you for your help.
Full path to the script should stand in the "command" section, e.g.:
insert_job: my_job job_type: c
command: C\:\Scripts\script1.bat
machine: appserver.domain.com
Alternative solution is to add C:\Scripts to the PATH variable on your app server.

send output to file from within shell script

I'm creating a script for users to run. I need to redirect the output to a file I'm creating from inside the script (hostname-date).
I have all the pieces except for how to copy the output of the script from inside the same script. All the examples I can find call the script and > it into the log, but this isn't an option.
-Alex
Add the following at the top of your script:
exec &> output.txt
It will make both stdin and stderr of the commands in the rest of your script go into the file output.txt.
exec in bash allows you to permanently redirect a FD (say, stdout) to a file.
A shell that calls a shell.
Have the first shell create the variable (hostname-date)
and call the second shell redirecting the output to the file.

Unix: Getting Export PATH to "Stick"

When setting the export path in Unix, example:
export PATH=$PATH: $EC2_HOME/bin
If I quit terminal and open it back up to continue working, I have to go through all the steps again, setting up the paths each time.
I'm wondering how I can set the path and have it "stick" so my system knows where to find everything the next time I open terminal without having to do it all over again.
Thanks!
Open ~/.bashrc. This file is loaded every time you start up a new shell (if you're using Bash, which most people are). If you're using a different shell, the file may have a different name, like ~/.shrc.
Add the line you need to the bottom of the file:
export PATH=$PATH:$EC2_HOME/bi
Other info rolled up from elsewhere in the thread:
There are multiple places to put this, depending on your shell and your needs. All of these files are in your home directory:
For Bash:
.bashrc (executed when you shart a shell)
OR
.bash_profile (executed when you log in)
For csh and tcsh:
.cshrc
For sh and ksh:
.profile
Add it to your .cshrc file (for csh and tcsh), .profile file (for sh and ksh), or .bash_profile file (for bash)
You need to find your profile file and put that line in there. Suppose you use bash, the profile files are .bashrc and .bash_profile, found in ~. These files will vary depending on which shell you use.
You have to put those commands into one of the "autostart" files of your shell.
For bash this would be .bashrc in your homedirectory (create it if necessary)
add it to your .bashrc or another .bash startup file.
... and for ksh edit .profile.

Resources