is there a .bash_profile file somewhere

Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions
Author Message
al_c
DD-WRT Guru


Joined: 13 Apr 2013
Posts: 2134
Location: Ottawa Canada

PostPosted: Sun Oct 20, 2019 15:12    Post subject: is there a .bash_profile file somewhere Reply with quote
I use PuTTY on Windows to run a variety of commandline scripts on my router(s). I'd like to create a number of aliases to shortcut the commands that I run on a regular basis... similar to this article https://dev.to/jenniferlynparsons/a-few-ways-i-use-bash-2mhh

I can't seem to find the .bash_profile file. Am I missing it? Should I be looking in the PuTTY config files rather than in DD-WRT?

Hint/tips would be appreciated.

Al
Sponsor
Wildlion
DD-WRT Guru


Joined: 24 May 2016
Posts: 1407

PostPosted: Mon Oct 21, 2019 0:44    Post subject: Reply with quote
Al

I think what you are looking for is /etc/profile
al_c
DD-WRT Guru


Joined: 13 Apr 2013
Posts: 2134
Location: Ottawa Canada

PostPosted: Mon Oct 21, 2019 1:01    Post subject: Reply with quote
Wildlion wrote:
Al

I think what you are looking for is /etc/profile


I missed that... however, /etc/profile is readonly...
SurprisedItWorks
DD-WRT Guru


Joined: 04 Aug 2018
Posts: 1444
Location: Appalachian mountains, USA

PostPosted: Mon Oct 21, 2019 16:55    Post subject: Reply with quote
You'll have to investigate to see whether you can do something similar in a Windows/PuTTY environment, with which I am not familiar, but ssh in linux can be used noninteractively to send a particular command to dd-wrt. That has let me create aliases on my linux laptop to do specific actions in dd-wrt, like "v" to cause the dd-wrt vpn client to restart. It's easy enough as well to send short sequences of commands.

I create longer dd-wrt scripts, say up to 20 lines, without using /jffs by simply including something like this in the Startup Commands of the Administration>Commands GUI page:
Code:
cat <<'EOF' >myscript
#!/bin/sh
command
command
.
.
.
EOF
chmod +x myscript

This creates an executable script in /tmp/root/myscript using the so-called "here document" feature of linux shells. I can then either execute the script interactively in ssh or use the noninteractive approach described above to run it.

_________________
2x Netgear XR500 and 3x Linksys WRT1900ACSv2 on 53544: VLANs, VAPs, NAS, station mode, OpenVPN client (AirVPN), wireguard server (AirVPN port forward) and clients (AzireVPN, AirVPN, private), 3 DNSCrypt providers via VPN.
yoyoma2
DD-WRT User


Joined: 24 Sep 2016
Posts: 371

PostPosted: Mon Oct 21, 2019 22:29    Post subject: Reply with quote
Setup a startup command to run a script that does things similar to this. Notice the last one needs an argument so uses a function instead of an alias.
Code:
# setup a ~/.profile file
OUTFILE=/tmp/root/.profile

rm -f $OUTFILE
echo "export PATH=\$PATH:." >> $OUTFILE
echo "export LANG=en_US.UTF-8" >> $OUTFILE
echo "alias la='ls -lahrt'" >> $OUTFILE
echo "alias h='history'" >> $OUTFILE
echo -e "psg() { ps | grep -i \"\$@\" | grep -v grep\n}" >> $OUTFILE

You need to run the script and logout+login for the changes to take effect.
al_c
DD-WRT Guru


Joined: 13 Apr 2013
Posts: 2134
Location: Ottawa Canada

PostPosted: Wed Oct 23, 2019 16:20    Post subject: Reply with quote
yoyoma2 wrote:
Setup a startup command to run a script that does things similar to this. Notice the last one needs an argument so uses a function instead of an alias.
Code:
# setup a ~/.profile file
OUTFILE=/tmp/root/.profile

rm -f $OUTFILE
echo "export PATH=\$PATH:." >> $OUTFILE
echo "export LANG=en_US.UTF-8" >> $OUTFILE
echo "alias la='ls -lahrt'" >> $OUTFILE
echo "alias h='history'" >> $OUTFILE
echo -e "psg() { ps | grep -i \"\$@\" | grep -v grep\n}" >> $OUTFILE

You need to run the script and logout+login for the changes to take effect.


Thanks everyone for chiming in. It's remarkably simple once you figure it out!

As suggested, I've created an alias.sh file which I store on my USB drive. I've added to the startup commands:
Code:
cp /opt/YAMon4/alias.sh $HOME/.profile


I use $HOME for the path because I run several different firmware variants and the location where .profile is stored changes for each.

In my alias.sh, I've also added:
Code:
alias cpa="cp /opt/YAMon4/alias.sh $HOME/.profile ; . $HOME/.profile"


This means that I can edit alias.sh and then run `cpa` to easily refresh my aliases...

I love learning new shit

Al
Wildlion
DD-WRT Guru


Joined: 24 May 2016
Posts: 1407

PostPosted: Wed Oct 23, 2019 21:58    Post subject: Reply with quote
great that you found it. Sorry I pointed you to a read only one... I thought that was what you were looking for at the time, such as to verify settings or something. I also forget that I have mounted over some of the partitions Shocked
al_c
DD-WRT Guru


Joined: 13 Apr 2013
Posts: 2134
Location: Ottawa Canada

PostPosted: Wed Oct 23, 2019 22:11    Post subject: Reply with quote
Wildlion wrote:
great that you found it. Sorry I pointed you to a read only one... I thought that was what you were looking for at the time, such as to verify settings or something. I also forget that I have mounted over some of the partitions Shocked


NP!
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum