create .bash_profile type file

Status
Not open for further replies.

nojohnny101

Wizard
Joined
Dec 3, 2015
Messages
1,478
This might be a simple answer but I wanted to double check with you guys before I go ahead and create it as it will be through the CLI and I don't want to mess something up by placing it in the wrong place.

Short: I want to create a file similar to the .bash_profile file I have on my computer where I have created alias for common commands I run.

Questions:
1) Does it matter where I place this file in regards to it working, and so ideally it can be backed up (I have recursive snapshots setup on my top level dataset)
2) I am assuming I can run the shortcut commands from anywhere in the CLI (I don't have to be in a specific location)
3) Anything else I should consider?

Thanks for your help!
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
1) Yes, it must be in your home directory, but I guess you can put the file where you want and make a symbolic link to it in your home directory, it may not work but it's easy to test.

2) Yes.

3) No.
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
3) Anything else I should consider?
If you're a regular user, the .bash_profile file will have no effect when you sudo or su. @Bidule0hm, do you know how to
  1. make sure bash is the shell when you su or sudo
  2. set up a .bash_profile or similar for that situation?
In my jails, where I log in as root, .bash_profile did not work. I had to put aliases and such in a .bashrc file in /root.
 

nojohnny101

Wizard
Joined
Dec 3, 2015
Messages
1,478
Thanks both of you for commenting. Most of the times I ssh in as root on my main box and run the script that way. So that is my first goal. I would like to run the same script on my backup box but I do have to run that as normal user and thus have to use "sudo" before the command.

I tried creating an alias called ".bash_profile" as soon as I ssh in as root. Once I save it, and try to run the shortcut, it says command not found. I tried also putting the same alias in ".bashrc" file but after saving, same error, command not found.

What am I doing wrong?
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
Thanks both of you for commenting. Most of the times I ssh in as root on my main box and run the script that way. So that is my first goal. I would like to run the same script on my backup box but I do have to run that as normal user and thus have to use "sudo" before the command.

I tried creating an alias called ".bash_profile" as soon as I ssh in as root. Once I save it, and try to run the shortcut, it says command not found. I tried also putting the same alias in ".bashrc" file but after saving, same error, command not found.

What am I doing wrong?
One thing is, if you just create it, the shell won't see it until you log in again or you source .bash_profile
I assume you're saving it in /root? You might try calling it .bashrc. But even then it probably won't work for sudo without some trick that I don't know.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
If you're a regular user, the .bash_profile file will have no effect when you sudo or su. @Bidule0hm, do you know how to
  1. make sure bash is the shell when you su or sudo
  2. set up a .bash_profile or similar for that situation?
In my jails, where I log in as root, .bash_profile did not work. I had to put aliases and such in a .bashrc file in /root.

1) Yep, look at the chsh command ;)

2) I don't use bash as I find tcsh much better so I'm not sure there's anything special besides putting the file in your home directory. NB: the home directory of the root user is not /home/root but /root.
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
I read somewhere it's not a good idea to permanently change the root shell. I don't know.

I found when I add an alias to /root/.cshrc, the alias works when I promote myself to superuser with su, but it doesn't work when I sudo.

Here's another weird thing. I want to add a folder to sudo's PATH so that I can type script names without giving the path. sudo gets the directory in PATH, but can't find a script that's there in the last directory listed
Code:
[jim@Tabernacle /root]$ sudo echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/mnt/Ark/Jim/bin:/mnt/Ark/Jim/bin
[jim@Tabernacle /root]$ sudo spinpid2.sh
sudo: spinpid2.sh: command not found
 

nojohnny101

Wizard
Joined
Dec 3, 2015
Messages
1,478
Well I ended up just setting it up as a cron job. It kind of accomplished what I wanted to.

Thanks for your scripts @Bidule0hm !
 
Status
Not open for further replies.
Top