PDA

View Full Version : bash



chrisackford
22nd August 2008, 03:29 AM
Hi, i am making a guess that my problem is with bash... i created a user and when i log into SSH i get this


-bash-3.2$

whereas i like it like this... because i can see what DIR i am in etc..


[root@mybox ~]#

does anyone have any ideas why? and how i can fix this?

Thanks, Chrisackford

Hlingler
22nd August 2008, 03:32 AM
Moved to General Support

V

chrisackford
22nd August 2008, 03:37 AM
sorry for putting it in the wrong place.

Hlingler
22nd August 2008, 03:39 AM
Not a problem. :)

Let's hope that I did put it in the right place! :D

V

daverj
22nd August 2008, 03:43 AM
you are addressing the issue of setting up your environment: prompts, path, aliases, etc. Try doing a google search on something like "setting up the bash environment". I'm sure you will get numerous hits. The reason I suggest that instead of giving you a quick fix is that you really need to know how to setup your environment if you are going to be efficient.

davidj

ivancat
22nd August 2008, 08:31 AM
do
set | grep PS1

if it is not something like
[\u@\h \W]$
then add this to your ~/.bashrc

PS1='[\u@\h \W]$'
and you might get what you want

chrisackford
22nd August 2008, 10:13 AM
you are addressing the issue of setting up your environment: prompts, path, aliases, etc. Try doing a google search on something like "setting up the bash environment". I'm sure you will get numerous hits. The reason I suggest that instead of giving you a quick fix is that you really need to know how to setup your environment if you are going to be efficient.

davidj
Hi, davidj. i looked at google and tryed a few things that i found and none of them worked

do
set | grep PS1

if it is not something like
[\u@\h \W]$
then add this to your ~/.bashrc

PS1='[\u@\h \W]$'
and you might get what you want
Hi ivancat, i did that and it doesnt work.. :confused:


-bash-3.2$ ls -a
. .. .bashrc cgi-bin error html icons site usage .viminfo
-bash-3.2$ cat .bashrc
PS1='[\u@\h \W]$'
-bash-3.2$ set | grep PS1
PS1='\s-\v\$ '
there was no .bashrc to begin with.. and i have tryed restarting the ssh terminal with no avail.

anymore ideas?

Thanks,
Chris

ivancat
22nd August 2008, 10:29 AM
then just issue the following:

PS1='[\u@\h \W]$'
and tell the results

chrisackford
22nd August 2008, 10:34 AM
that works.

-bash-3.2$
PS1='[\u@\h \W]$'
[vidko@ks359925 site]$

okay, so why is it not working via the .bashrc?

Thanks, Chrisackford

ivancat
22nd August 2008, 10:37 AM
because site IS NOT your home directory, your home directory is something like /home/vidko :rolleyes:

so, do:

cd ~
and after that edit .bashrc that should be here

chrisackford
22nd August 2008, 10:48 AM
because site IS NOT your home directory, your home directory is something like /home/vidko :rolleyes:

so, do:

cd ~
and after that edit .bashrc that should be here
i was in my home dir when i created the .bashrc file ;)


[vidko@ks359925 ~]$cd ~
[vidko@ks359925 ~]$ls -A
.bashrc cgi-bin error html icons .mysql_history site tclhttpd usage .viminfo
[vidko@ks359925 ~]$cat .bashrc
PS1='[\u@\h \W]$'
[vidko@ks359925 ~]$

(still set via PS1='[\u@\h \W]$')

Thanks, Chris

EDIT: By the way i am on Fedora 8 Server if that makes any difference?

ivancat
22nd August 2008, 10:54 AM
EDIT: By the way i am on Fedora 8 Server if that makes any difference?

No, it doesn't really matter.

To check if bash reads the .bashrc file at all add something like

echo "Hello, world!"

and see if it is printed when you start the shell

chrisackford
22nd August 2008, 11:19 AM
No, it doesn't really matter.

To check if bash reads the .bashrc file at all add something like

echo "Hello, world!"

and see if it is printed when you start the shell


login as: vidko
vidko@box's password:
Last login: Fri Aug 22 11:05:10 2008 from host
Fedora release 8 (Werewolf)

-bash-3.2$ ls -A
.bashrc cgi-bin error html icons .mysql_history site tclhttpd usage .viminfo
-bash-3.2$ cat .bashrc
PS1='[\u@\h \W]$'
echo "Hello, world!"
-bash-3.2$

so, it's not reading it then.

any ideas?


-bash-3.2$ ls -lsA
total 40
4 -rw-r--r-- 1 vidko vidko 39 2008-08-22 12:15 .bashrc
4 drwxr-xr-x 2 vidko vidko 4096 2008-07-14 21:31 cgi-bin
4 drwxr-xr-x 3 vidko vidko 4096 2008-08-22 10:48 error
4 drwxr-xr-x 2 vidko vidko 4096 2008-07-14 21:31 html
4 drwxr-xr-x 3 vidko vidko 4096 2008-08-22 10:48 icons
4 -rw------- 1 vidko vidko 21 2008-08-22 11:16 .mysql_history
4 drwxr-xr-x 3 vidko vidko 4096 2008-08-22 11:15 site
4 drwxr-xr-x 4 root root 4096 2008-08-22 11:20 tclhttpd
4 drwxr-xr-x 2 vidko vidko 4096 2008-08-22 10:49 usage
4 -rw------- 1 vidko vidko 649 2008-08-22 12:15 .viminfo


Thanks, Chris

ivancat
22nd August 2008, 11:26 AM
try creating following files as well .bash_profile, containing:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME

.bash_logout

clear

.bash_history

#this is empty

chmod them to 0644 and restart shell.

p.s. the last 2 are not really necessary, but they are useful (e.g. history file to browse commands executed)

chrisackford
22nd August 2008, 11:40 AM
try creating following files as well .bash_profile, containing:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME

.bash_logout

clear

.bash_history

#this is empty

chmod them to 0644 and restart shell.

p.s. the last 2 are not really necessary, but they are useful (e.g. history file to browse commands executed)
okay that works.. but now i get an error

-bash: sh_profile: command not found
and i cant find any reference to sh_profile anywhere.

Thanks, Chris

ivancat
22nd August 2008, 11:57 AM
when do you get this error?

chrisackford
22nd August 2008, 12:03 PM
when do you get this error?


login as: vidko
vidko@mybox's password:
Last login: Fri Aug 22 11:31:42 2008 from host
Fedora release 8 (Werewolf)
Linux *** 2.6.24.5-grsec-xxxx-grs-ipv4-32 #3 SMP Wed May 28 09:09:25 CEST 2008 i686 i686 i386 GNU/Linux

server : 51847
ip : ***
hostname : ***

-bash: sh_profile: command not found
[vidko@ks359925 ~]#


it is above the first bash prompt in the code above. it is the first time i have seen it.

Thanks, Chris

ivancat
22nd August 2008, 12:16 PM
hmm, just a guess, but that error may appear if one of the files cannot be read (e.g. /etc/profile)

chrisackford
22nd August 2008, 12:26 PM
hmm, just a guess, but that error may appear if one of the files cannot be read (e.g. /etc/profile)
it's not stopping me from doing anything so i'm not worrying too much at the moment :)

Thanks, Chris

chrisackford
22nd August 2008, 03:28 PM
hmm, just a guess, but that error may appear if one of the files cannot be read (e.g. /etc/profile)

also i cant to commands like


shutdown -r now

i have to type the full path =[

Thanks,
Chris

ivancat
22nd August 2008, 03:58 PM
shutdown command is not normally available for normal users, you may use reboot instead

chrisackford
22nd August 2008, 04:03 PM
shutdown command is not normally available for normal users, you may use reboot instead
i was doing it a a superuser (root) and it said

bash: shutdown: command not found

Thanks Chris

ivancat
22nd August 2008, 04:07 PM
hmm, looks like you have problems with bash profiles for all users, check the path for root

set | grep PATH

should be something like this:

PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

chrisackford
22nd August 2008, 04:13 PM
hmm, looks like you have problems with bash profiles for all users, check the path for root

set | grep PATH

should be something like this:

[root@ks359925 ~]# set | grep PATH
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
and i just rebooted it and it seems to have fixed that problem =]

Thanks, Chris

ivancat
22nd August 2008, 04:16 PM
and i just rebooted it and it seems to have fixed that problem =]

Thanks, Chris[/QUOTE]

that's good

chrisackford
22nd August 2008, 04:22 PM
and i just rebooted it and it seems to have fixed that problem =]

Thanks, Chris

that's good[/QUOTE]
well it fixed that problem anyway, loads more.. lol it's funny when i set my server up at home it worked first time i had no issues but on the dedicated server i have had nothing but trouble. :(

Thanks, Chris

ivancat
22nd August 2008, 04:40 PM
well it fixed that problem anyway, loads more.. lol it's funny when i set my server up at home it worked first time i had no issues but on the dedicated server i have had nothing but trouble. :(

Thanks, Chris

Yeah, that's strange indeed. Even though fedora is not recommended for server environments, I still can't get why you've got troubles with things like bash.

chrisackford
22nd August 2008, 05:08 PM
Yeah, that's strange indeed. Even though fedora is not recommended for server environments, I still can't get why you've got troubles with things like bash.
i have troubles with PHP not saving/reading session data too :( it's being stupid. what would you recomend for server enviroment? i like fedora because i know my way around it well.

Thanks, Chris

ivancat
22nd August 2008, 05:13 PM
I'd recommend CentOS, use it on servers I maintain. It's also rpm-based and server-oriented.

chrisackford
22nd August 2008, 05:25 PM
i think i will download that and try it on a vbox see if i like it :)

briantan
22nd August 2008, 06:26 PM
Hi chrisackford

Upon login, bash first source /etc/profile and then ~/.bash_profile

~/.bash_profile in turn source the following
~/.bashrc
/etc/bashrc

Please check existence of these files:


rw-r--r-- /etc/profile #--- system-wide environment and startup programs
rw-r--r-- /etc/bashrc #--- system-wide functions and aliases
rw-r--r-- ~/.bash_profile #--- user-specific environment and startup programs
rw-r--r-- ~/.bashrc #--- user-specific functions and aliases

PS1 is setup by default in /etc/bashrc .

Following are default codes for these profiles in case you are missing any:


# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}

# ksh workaround
if [ -z "$EUID" -a -x /usr/bin/id ]; then
EUID=`id -u`
UID=`id -ru`
fi

# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
fi

# No core files by default
ulimit -S -c 0 > /dev/null 2>&1

if [ -x /usr/bin/id ]; then
USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi

HOSTNAME=`/bin/hostname`
HISTSIZE=1000

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
. $i
fi
done

unset i
unset pathmunge


# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME
This is same as what ivancat given you. I think you had a typo at first line in ~/.bash_profile


# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi



# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# By default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ $UID -gt 99 ] && [ "`id -gn`" = "`id -un`" ]; then
umask 002
else
umask 022
fi

# are we an interactive shell?
if [ "$PS1" ]; then
case $TERM in
xterm*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
else
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
fi
;;
screen)
if [ -e /etc/sysconfig/bash-prompt-screen ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
else
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"'
fi
;;
*)
[ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
;;
esac
# Turn on checkwinsize
shopt -s checkwinsize
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
fi

if ! shopt -q login_shell ; then # We're not a login shell
# Need to redefine pathmunge, it get's undefined at the end of /etc/profile
pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}

# Only run profile.d scripts if we are no login shell and interactive
if [ "$PS1" ]; then
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
. $i
fi
done
fi
unset i
unset pathmunge
fi
# vim:ts=4:sw=4

Hope this helps.

vallimar
22nd August 2008, 06:41 PM
Just copy the .bash* files from /etc/skel to your homedir -- Sounds like you did things by hand instead of allowing the tools to do their thing.

chrisackford
22nd August 2008, 07:04 PM
Hi chrisackford

Upon login, bash first source /etc/profile and then ~/.bash_profile

~/.bash_profile in turn source the following
~/.bashrc
/etc/bashrc

Please check existence of these files:


rw-r--r-- /etc/profile #--- system-wide environment and startup programs
rw-r--r-- /etc/bashrc #--- system-wide functions and aliases
rw-r--r-- ~/.bash_profile #--- user-specific environment and startup programs
rw-r--r-- ~/.bashrc #--- user-specific functions and aliases

PS1 is setup by default in /etc/bashrc .

Following are default codes for these profiles in case you are missing any:


# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}

# ksh workaround
if [ -z "$EUID" -a -x /usr/bin/id ]; then
EUID=`id -u`
UID=`id -ru`
fi

# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
fi

# No core files by default
ulimit -S -c 0 > /dev/null 2>&1

if [ -x /usr/bin/id ]; then
USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi

HOSTNAME=`/bin/hostname`
HISTSIZE=1000

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
. $i
fi
done

unset i
unset pathmunge


# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME
This is same as what ivancat given you. I think you had a typo at first line in ~/.bash_profile


# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi



# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# By default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ $UID -gt 99 ] && [ "`id -gn`" = "`id -un`" ]; then
umask 002
else
umask 022
fi

# are we an interactive shell?
if [ "$PS1" ]; then
case $TERM in
xterm*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
else
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
fi
;;
screen)
if [ -e /etc/sysconfig/bash-prompt-screen ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
else
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"'
fi
;;
*)
[ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
;;
esac
# Turn on checkwinsize
shopt -s checkwinsize
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
fi

if ! shopt -q login_shell ; then # We're not a login shell
# Need to redefine pathmunge, it get's undefined at the end of /etc/profile
pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}

# Only run profile.d scripts if we are no login shell and interactive
if [ "$PS1" ]; then
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
. $i
fi
done
fi
unset i
unset pathmunge
fi
# vim:ts=4:sw=4

Hope this helps.
Hi, Thanks this fixed it all including the file not found error

Thanks, Chris

chrisackford
22nd August 2008, 07:06 PM
Just copy the .bash* files from /etc/skel to your homedir -- Sounds like you did things by hand instead of allowing the tools to do their thing.

Thanks for your help :)