Showing posts with label Script. Show all posts
Showing posts with label Script. Show all posts

Saturday, July 27, 2013

Untar all files in a directory

#!/bin/bash
for a in `ls -1 *.tar.*`
do
        tar -zxvf $a
done

http://castyour.net/untar-all-files-directory

Bash for loop examples
http://www.cyberciti.biz/faq/bash-for-loop/

Other arguments
http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/


tar error - 'Child returned status 1'
http://www.linuxquestions.org/questions/linux-newbie-8/tar-error-'child-returned-status-1'-208083/

You used "tar -zxvf" for the second command. the 'z' option tells tar to use gzip to uncompress the file. Since you already uncompressed it in the first command, gzip doesn't know what to do with it, and it consequently croaks. Tar stops because gzip encountered a problem. So, with the file you have now, you would extract it with:
tar -xvf xxxxxx.x.x.tar

I would go back and re-gzip the tar file though (to save space):
gzip xxxxxx.x.x.tar
tar -zxvf xxxxxx.x.x.tar.gz


The first step uncompresses the tar ball.
In the second step, tar is expecting a compressed tar ball (.tar.gz).

You can either do:
Code:
tar -xvf fileName.tar
for an uncompressed tar ball
or 
Code:
tar -xzvf fileName.tar.gz
for a compressed tar ball, as the z switch uncompresses the tar ball using gzip.

I hope this helps
--Ian

Tuesday, July 16, 2013

Password-less login

expect and automatic login

"expect" command is simply expecting a text from terminal, and send it when it meets expectation.
sudo apt-get install expect
Installation is done.

Sample usage.

Let's make simple shell program
vi abc.sh

Type into shell shell program.
#!/usr/bin/expect -f
set timeout 100
spawn ssh userid@servername 
expect "/home/devtrigger/.ssh/id_rsa" 
send "password\r"
expect "servername:"
send "bash\r"
interact



http://devtrigger.blogspot.com/2012/02/install-expect-on-ubuntu-11.html

http://greg-n-blog.blogspot.com/search/label/ssh

http://stackoverflow.com/questions/12202587/ssh-script-that-automatically-enters-password

http://stackoverflow.com/questions/4780893/use-expect-in-bash-script-to-provide-password-to-ssh-command

Friday, November 23, 2012

set terminal foreground/background color

setterm -term linux -back blue -fore white -clear

http://superuser.com/questions/248299/how-to-change-background-foreground-color-on-all-existing-terminals

http://matt-linux-log.blogspot.com/2010/09/change-tty-text-and-background-colour.html 


Bash Prompt HOWTO
http://www.faqs.org/docs/Linux-HOWTO/Bash-Prompt-HOWTO.html


Well explanation on Colors & Prompts in BASH
http://systhread.net/texts/200703bashish.php



 Other references and resource
Xterm Control Sequences
http://invisible-island.net/xterm/ctlseqs/ctlseqs.html

Xterm
http://en.wikipedia.org/wiki/Xterm

Terminal Color configuration:
http://www.pixelbeat.org/docs/terminal_colours/


More Detail visual examples:
https://wiki.archlinux.org/index.php/Color_Bash_Prompt


Modified:

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
 


PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[32m\]\$

Monday, October 15, 2012

Syntax error: Bad for loop variable

With sh or ksh, you must use a while statement.

Jean-Pierre.

http://www.unix.com/shell-programming-scripting/60860-loop-syntax-trouble.html

 chmod 755 xxxxx.sh

./xxxxx

Bash/Shell Programming – Binary Operator Expected

http://digitalvectorz.wordpress.com/2009/12/10/bashshell-programming-binary-operator-expected/


if [[ -n `ls | grep something` ]]; then
echo "Success";
fi




Nested if/then condition:
http://tldp.org/LDP/abs/html/nestedifthen.html


if [ "$a" -gt 0 ]
then
  if [ "$a" -lt 5 ]
  then
    echo "The value of \"a\" lies somewhere between 0 and 5."
  fi
fi