Showing posts with label shell. Show all posts
Showing posts with label shell. Show all posts

Tuesday, February 12, 2013

Give bash prompt an interactive value with a script

[CONTEXT]
Bash script to automatically give an interactive value to prompt.

[WHEN]
For instance, you need to execute a sudo command on user logon, and you need to do it through a script.

[HOW]
Edit a bash script with the following content:

#!/bin/sh

( echo 'P4ssw0rd
' ) | su - root -c "/sbin/rcnetwork restart"

Where:
P4ssw0rd is the password for root user
"/sbin/rcnetwork restart" is the command to execute as root user

Take special attention on the new line after the password on the bash script, and also on the single quotes.


[NOTE]
This is only for reference, you never should write out the root password on a plain text file.

Saturday, February 9, 2013

GNU Screen Command





[CONTEXT]
Window manager that multiplexes a physical terminal between several processes, typically interactive shells.

[WHEN]
Pair remote programming/assistance. Using the multiuser mode to do pair programming or create a teaching environment.

[HOW]
sudo apt-get install screen

1. Change user to the username you want to allow screen access

2. To start up screen:
  screen -S sessionname

3. Now instruct the second/remote user to SSH connect to your host/IP and to attach to the screen
  screen -x sessionname


Both will be able to interact in the same session.


[REFERENCES]
http://www.gnu.org/software/screen

GNU Privacy Guard (GPG)


[CONTEXT]
Encryption and Signing

[WHEN]
apt-get update

[ERROR]
GPG error: The following signatures were invalid KEYEXPIRED 1337087218
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY AED4B06F473041FA

[SOLUTION]
apt-get install debian-archive-keyring

[REFERENCES]
http://wiki.debian.org/Keysigning

Thursday, February 7, 2013

Adding directories to your PATH variable

Edit your .bashrc as user and add the line:

export PATH=$PATH:/path/to/directory

Enable programmable completion for user

Enable programmable completion for a user:
First install bash-completion package, as root user type

aptitude install bash-completion

and, just add the following lines to the /home/$USER/.bashrc (as $USER)

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

also the root user can have this feature, adding the same lines above in /root/.bashrc