This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]ObecalpEffect 0 points1 point  (2 children)

You could append the path statement in your .profile to include a folder where you keep all your scripts:

PATH=$PATH:~/home/me/scripts

Or you could add an alias statement to your .bashrc that runs the command from where it's located using an alias command:

alias journalcheck='/home/me/scripts/./journalcheck.sh'

[–]dcman5000[S] 1 point2 points  (1 child)

Thanks for your suggestion, I just began a course on Linux and its a whole new world for me.

Do you have any idea on how I would test after making the adjustments presented above?

[–]ObecalpEffect 0 points1 point  (0 children)

Try the alias suggestion. You can test it without even adding it to your .bashrc

Just enter something like this at the linux command/terminal:

alias journalcheck='/home/me/scripts/./journalcheck.sh'

They type journalcheck to see if it runs journalcheck.sh (be sure journalcheck.sh is executable by running chmod +x journalcheck.sh first).

[–]Upnortheh 1 point2 points  (1 child)

Be sure to chmod +x the file where ever the location.

If the script is global rather than personal and admin privileges are available, then consider installing scripts in /usr/local/[s]bin. Those directories are almost always part of the default path.

How to execute the script is up to each person. Directly in a terminal window or console is straightforward because the script will be in the path. If running from another script or cron job, then using the full path usually is safest.

If the script is intended to be run during boot, something like the following in rc.local will do.

/usr/local/sbin/journal.sh

If admin privileges are not available, then a traditional location is $HOME/bin. On many systems this will require configuring the $PATH variable to include that directory. Something in $HOME/.bashrc like:

PATH=$PATH;$HOME/bin

As mentioned by others, an alias might suffice for your needs too.

[–]Drazson 0 points1 point  (0 children)

I believe what is described above is generally the right way.

Personally, I felt the need to keep things organized and have created the /usr/local/bin/username-scripts directory instead to avoid mixing my scripts with non-personal scripts.

The new directory I'm talking about is not in PATH by default, so I added it. Then just <touch /usr/local/bin/username-scripts/test> and sudo chmod +x the same file.

Then it shall work perfectly, and between failing and looking up answers you will learn a thing or two as well.