/etc/bashrc help!
Dear all,
i've appended the below to /etc/bashrc it works like a charm with ssh connections though SFTP sessions fail since the below is being sent to the intiator. any way of limiting the below to none sftp sessions? or any other idea for it to work? # If id command returns zero, you’ve root access. if [ $(id -u) -eq 0 ]; then # you are root, set red colour prompt echo "############################################# ##" echo "### You are now working as ROOT. ###" echo "### Pay attention to what you type. ###" echo "############################################# ##" PS1="[$(tput setaf 1)]u@h:w #[$(tput sgr0)]" else # normal echo echo " ################################################## #########" echo "Welcome $(whoami), here's something to start your day with:" echo echo `sh /etc/lines.sh /etc/quotes.txt` echo " ################################################## ##########" echo PS1="[u@h:w] $" fi Thanks, --Roland _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos |
/etc/bashrc help!
I think "bash interactive shell" is what you want to search for.
Have a look at item 6.3.2 at <http://durak.org/sean/pubs/software/bash/bashref_25.html> (picked up arbitrarily from the search results). I *think* scp uses the shell non-interactively, but test to make sure. Either way, you should have that in bashrc in case there are other non-interactive shells in use (and there usually are). Devin _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos |
/etc/bashrc help!
I think you can add:
[ -z "$PS1" ] && return before your code. PS1 should be null for sftp connections. Mark Snyder Highland Solutions ----- Original Message ----- From: "Roland Roland" <R_O_L_A_N_D@hotmail.com> To: "CentOS mailing list" <centos@centos.org> Sent: Tuesday, April 19, 2011 12:18:38 PM Subject: [CentOS] /etc/bashrc help! Dear all, i've appended the below to /etc/bashrc it works like a charm with ssh connections though SFTP sessions fail since the below is being sent to the intiator. any way of limiting the below to none sftp sessions? or any other idea for it to work? # If id command returns zero, you’ve root access. if [ $(id -u) -eq 0 ]; then # you are root, set red colour prompt echo "############################################# ##" echo "### You are now working as ROOT. ###" echo "### Pay attention to what you type. ###" echo "############################################# ##" PS1="[$(tput setaf 1)]u@h:w #[$(tput sgr0)]" else # normal echo echo " ################################################## #########" echo "Welcome $(whoami), here's something to start your day with:" echo echo `sh /etc/lines.sh /etc/quotes.txt` echo " ################################################## ##########" echo PS1="[u@h:w] $" fi Thanks, --Roland _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos |
/etc/bashrc help!
On Tuesday 19 April 2011 20:18:38 Roland Roland wrote:
> Dear all, > > i've appended the below to /etc/bashrc it works like a charm with ssh > connections though SFTP sessions fail since the below is being sent to > the intiator. > any way of limiting the below to none sftp sessions? or any other idea > for it to work? > > > # If id command returns zero, you’ve root access. > if [ $(id -u) -eq 0 ]; > then # you are root, set red colour prompt > echo "############################################# ##" > echo "### You are now working as ROOT. ###" > echo "### Pay attention to what you type. ###" > echo "############################################# ##" > PS1="[$(tput setaf 1)]u@h:w #[$(tput sgr0)]" > else # normal > echo > echo " ################################################## #########" > echo "Welcome $(whoami), here's something to start your day with:" > echo > echo `sh /etc/lines.sh /etc/quotes.txt` > echo " ################################################## ##########" > echo > PS1="[u@h:w] $" > fi > Rolan, you have two choices: 1. Print the whole content on STDERR so you don't disturb the sftp 2. if [ "$-" != 'hBc' ]; then echo 'your content here'; fi If you go to the second option, the idea there is that $- is set to hBc every time you use the shell from SFTP (non-interactive mode). So you echo all the things you like only if it is an interactive shell. Marian _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos |
/etc/bashrc help!
On Wednesday 20 April 2011 00:26:04 Marian Marinov wrote:
> On Tuesday 19 April 2011 20:18:38 Roland Roland wrote: > > Dear all, > > > > i've appended the below to /etc/bashrc it works like a charm with ssh > > connections though SFTP sessions fail since the below is being sent to > > the intiator. > > any way of limiting the below to none sftp sessions? or any other idea > > for it to work? > > > > > > # If id command returns zero, you’ve root access. > > if [ $(id -u) -eq 0 ]; > > then # you are root, set red colour prompt > > echo "############################################# ##" > > echo "### You are now working as ROOT. ###" > > echo "### Pay attention to what you type. ###" > > echo "############################################# ##" > > PS1="[$(tput setaf 1)]u@h:w #[$(tput sgr0)]" > > else # normal > > echo > > echo " ################################################## #########" > > echo "Welcome $(whoami), here's something to start your day with:" > > echo > > echo `sh /etc/lines.sh /etc/quotes.txt` > > echo " ################################################## ##########" > > echo > > PS1="[u@h:w] $" > > fi > > Rolan, you have two choices: > > 1. Print the whole content on STDERR so you don't disturb the sftp > > 2. if [ "$-" != 'hBc' ]; then echo 'your content here'; fi > > If you go to the second option, the idea there is that $- is set to hBc > every time you use the shell from SFTP (non-interactive mode). So you echo > all the things you like only if it is an interactive shell. > > Marian Just to make things clear, this is from the bash manual: An interactive shell is one started without non-option arguments and without the -c option whose standard input and error are both connected to terminals (as determined by isatty(3)), or one started with the -i option. PS1 is set and $- includes i if bash is interactive, allowing a shell script or a startup file to test this state. You can also test if you want with these two tests: if [[ "$-" =~ 'i' ]]; then echo interactive; fi if ( echo $- |grep i > /dev/null ); then echo interactive; fi Marian -- Best regards, Marian Marinov _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos |
/etc/bashrc help!
Roland Roland wrote:
> > Dear all, > > i've appended the below to /etc/bashrc it works like a charm with ssh > connections though SFTP sessions fail since the below is being sent to > the intiator. > any way of limiting the below to none sftp sessions? or any other idea > for it to work? I have the following in a bashrc for this same reason, it works fine: # print a fortune in new interactive terminals # the test for $PS1 (value of the prompt) makes sftp work if [ -n "$PS1" ] ; then fortune ; echo fi _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos |
| All times are GMT. The time now is 12:49 PM. |
VBulletin, Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.