Softpanorama
(slightly skeptical) Open Source Software Educational Society

May the source be with you, but remember the KISS principle ;-)

Softpanorama Search

Shellorama 2003

Prev : Index  : Next

freshmeat.net Project details for ddclient ddclient by Monarch - Jul 17th 2003 05:40:18

I had some trouble with ddclient as well. So I developed a short bash-script that updates the hosts ip-address on dyndns.org when changed:

#!/bin/bash
export LANG="default"
ipneu=`/sbin/ifconfig *interface* | grep inet | awk '{print $2}' | sed 's#addr:##g'`
set `cat /var/spool/ipalt`
ipalt=$1
if [ "$ipalt" == "$ipneu" ]
then
echo "nochg">>/var/log/dyndnslog
else
echo "updating">>/var/log/dyndnslog
echo $ipneu>/var/spool/ipalt
wget -a /var/log/dyndnslog "http://*username*:*passwd*@members.dyndns.org/nic/update?system=dyndns&hostname=*mydomain*" -O /var/log/dyndnsres
cat /var/log/dyndnsres>>/var/log/dyndnslog
fi


To configure this script replace the following words:
*interface* name of the interface to fetch the IP from i.e. ppp0
*username* username of dyndns.org-account
*passwd* password to this account
*mydomain* hostname of the accounts domain to be updated ie. mydomain.dyndns.org

now save it to a directory that's in the search path ie.: /usr/sbin/updatedyndns
set the apropiate rights to this file to make it executable. ie.: chmod 4755 /usr/sbin/updatedyndns
add a script to the ppp/ip-up.d directory to make the machine execute the script everytime a new ppp-connection is made.

This script has no error-handling but it worked best for me so far. U might have noticed that this needs wget to be installed.

--
- Just because you're paranoid, it don't mean they're not after you.

Re:My personal favorite; (Score:2)
by 26199 (577806) * on Wednesday March 10, @08:54PM (#8527893)
(http://www.davidmorgan.org/)
:(){ :|:&};:

It reads... define function ':' as follows: pipe the output from function ':' into function ':' -- do that in the background (ie fork). Call the function ':'.

I had no idea how it worked, either, but I looked it up :-)
My favourite shell script... (Score:2)
by cperciva (102828) on Wednesday March 10, @03:09PM (#8524266)
(http://www.daemonology.net/)
... is FreeBSD Update [daemonology.net]. 700 lines of shell code to fetch, install, and rollback security updates to an entire operating system.
Tab completion (Score:3, Informative)
by Spy Hunter (317220) on Wednesday March 10, @03:03PM (#8524210)
(http://www.xwt.org/ | Last Journal: Saturday February 23, @04:33AM)
In Debian, the Bash package comes with a totally awesome collection of customized tab completions. For some reason, they are not turned on by default.

To turn them on in a single account, you can put the line "source /etc/bash_completion" in your ~/.bashrc file, or you can turn them on globally by editing the /etc/bash.bashrc file and uncommenting the relevant lines.

You'll get magic smart tab completion for cd, apt-get, ssh, mplayer, and bajillions of other programs, and you'll wonder how you ever did without it. apt-get tab completion in particular rocks like nothing else.

For example, if you type "apt-get remove x[TAB]" you'll get a complete list of installed packages starting with x. When installing, you'll get a list of available but not yet installed packages. I can't stand using apt-get without tab completion anymore.

pushd and popd (and other tricks) (Score:5, Informative)
by Komi (89040) <cgguenNO@SPAMattglobal.net> on Wednesday March 10, @02:41PM (#8524004)
(http://slashdot.org/)
I've read throught the tcsh man pages and stole from other people and probably the least-known most useful trick I've found is pushd and popd (which I realias to pd and po), and of course directory stack substitution. Here's a snippet of code that's really useful:

alias pd pushd
alias po popd
cd /incredi/bly/long/path/name
pd /some/other/incredi/bly/long/path/name
cp *.mp3 =1 # =1 is the first entry on the dirstack
po # returns you back to first place

The other major time saver I use are sed and awk. I used each for a specific purpose. Sed works great for substitution, and awk I use to grab columns of data. Here's a sample of how I'd use both together. This will list the home directories of the users on a machine. It's simple, but there's a ton you can do with this technique.

who | awk '{print $1}' | sort | uniq | sed 's@^@/home/@g'

Here's other stuff I have grouped by sections in my .cshrc

First, I have my shell variables. The comments say what they do. The most important one is autolist.

set autolist # automatically lists possibilities after ambiguous completion
set dunique # removes duplicate entries in the dirstack
set fignore=(\~) # files ending in ~ will be ignored by completion
set histdup=prev # do not allow consecutive duplicate history entries
set noclobber # output redirection will not overwrite an existing file
set notify # notifies when a job completes
set symlinks=ignore # treats symbolic directories like real directories
set time=5 # processes that run longer than $time seconds will be timed.

Second, bindkeys are pretty neat. I rebind the up and down arrow keys. By default they scroll up and down one at a time through the history. You can bind them to search the history based on what you've typed so far.

bindkey -k up history-search-backward # up arrow key
bindkey -k down history-search-forward # down arrow key

Third, completes allow for customizing tab completion. When I change directories, tab only completes directory names. This also works for aliases, sets, setenvs, etc.

complete cd 'p/1/d/'
complete alias 'p/1/a/'
complete setenv 'p/1/e/'
complete set 'p/1/s/'

Fourth, I have all my aliases. I had to cut a bunch because of the lameness filter.

alias cwdcmd 'ls'
alias precmd 'echo -n "\033]0;$USER@`hostname` : $PWD\007"'
alias pd 'pushd'
alias po 'popd'
alias dirs 'dirs -v'
alias path 'printf "${PATH:as/:/\n/}\n"'
alias ff 'find . -name '\''\!:1'\'' -print \!:2*'
alias aw 'awk '\''{print $'\!:1'}'\'''
alias sub 'sed "s@"\!:1"@"\!:2"@g"'

Re:pushd and popd (and other tricks) (Score:1)
by MasterLock (581630) on Wednesday March 10, @03:23PM (#8524465)
Two of my most handy aliases (tcsh and 4DOS/4NT) are:

alias mcd 'md \!*; cd \!*'

alias rcd 'setenv OLD_DIR `pwd`;cd ..;echo $OLD_DIR;rd "$OLD_DIR"; unsetenv OLD_DIR' Usage: ~/> mcd junkDir ~/junk> -- do commands, unzip files, et cetera -- ~/junk> rcd ~/> -- back where you were and the dir is gone --

Re:pushd and popd (and other tricks) (Score:1, Informative)
by Anonymous Coward on Wednesday March 10, @03:25PM (#8524497)
alias pd pushd
alias po popd
cd /incredi/bly/long/path/name
pd /some/other/incredi/bly/long/path/name
cp *.mp3 =1 # =1 is the first entry on the dirstack
po # returns you back to first place


cd /some/directory/
cd /another/directory/
cp *.mp3 ~-
cd ~-
Re:pushd and popd (and other tricks) (Score:2, Informative)
by MasterLock (581630) on Wednesday March 10, @03:33PM (#8524577)
Two of my most handy aliases (tcsh and 4DOS/4NT) are:

alias mcd 'md \!*; cd \!*'
alias rcd 'setenv OLD_DIR `pwd`;cd ..;echo $OLD_DIR;rd "$OLD_DIR"; unsetenv OLD_DIR'

Usage:
  ~/> mcd junkDir
  ~/junk> -- do commands, unzip files, et cetera --
  ~/junk> rcd
  ~/> -- back where you were and the dir is gone --
Quick Hacks (Score:5, Informative)
by frodo from middle ea (602941) on Wednesday March 10, @02:06PM (#8523604)
(http://aol.com/)
My 2 cent tips on budding shell script authors.

If the script is not working as you want, put a

set -x

on the fist line and

set +x

on the last line.

You will see the exact execution path and variable expansion, very neat for debugging

Re:Quick Hacks (Score:5, Informative)
by Stinky Cheese Man (548499) on Wednesday March 10, @02:15PM (#8523713)
In bash, at least, you can do this even more simply with...

sh -x scriptname

Re:Quick Hacks (Score:1)
by Tore S B (711705) on Wednesday March 10, @03:46PM (#8524725)
(http://tore.nortia.no/)
Actually, that's
bash -x scriptname

Just because sh is symlinked to bash with Linux, doesn't mean that standard /bin/sh is completely gone. Solaris puts it in /usr/gnu/bash. Same with IRIX 
Re:killing processes by name... (Score:1)
by Durin_Deathless (668544) on Wednesday March 10, @03:16PM (#8524350)
(http://tuxserver.ath.cx/~durin/)
I prefer

killall -9 [procname]

but that's just me.

Re:killing processes by name... - (Score:1)
by timbrown (578202) <slashdot@machine.org.uk> on Wednesday March 10, @05:36PM (#8526039)
(http://www.machine.org.uk/)
Erm, Solaris has pkill and pgrep for killing and locating process by name and other process attributes.
 
Now run it. (Score:2, Informative)
by Chris Burke (6130) on Wednesday March 10, @04:01PM (#8524910)
(http://slashdot.org/)
$ uname -a
SunOS 5.8 Generic_108528-27 sun4m sparc SUNW,SPARCstation-20
$ which killall /usr/sbin/killall
Re:pushd and popd (and other tricks) (Score:2)
by cballowe (318307) on Wednesday March 10, @04:42PM (#8525394)
(http://www.steelballs.org/)

who | awk '{print $1}' | sort | uniq | sed 's@^@/home/@g'

What you really mean is

who | awk '{print $1}' | sort -u | sed 's@^@/home/@'

Which does make the assumption that user home dirs are /home/username -- not always the case. Safer is:

awk -F: '{print $6}' /etc/passwd

Remember, there's a limited number of keystrokes in a lifetime - use them wisely.
 

Re:pushd and popd (and other tricks) (Score:1)
by camh (32881) on Wednesday March 10, @06:25PM (#8526528)

alias pd pushd

alias po popd

Similar to what I have, except I use pp instead of pd (because its faster to type) and pp without args takes you to your home directory (like cd without args). To go along with it, I use

alias r "pushd +1"

alias rr "cd "$OLDPWD"

If you're working within a number of directories, use pp to get to them and then use r to rotate between the directories. rr is convenient to quickly cd somewhere else to do something and then get back again.

Re:pushd and popd (and other tricks) (Score:2)
by Ramses0 (63476) on Wednesday March 10, @07:39PM (#8527252)
My favorite "Nifty" was when I spent the time to learn about "xargs" (I pronounce it zargs), and brush up on "for" syntax.

    ls | xargs -n 1 echo "ZZZ> "

Basically indents (prefixes) everything with a "ZZZ" string. Not really useful, right? But since it invokes the echo command (or whatever command you specify) $n times (where $n is the number of lines passed to it) this saves me from having to write a lot of crappy little shell scripts sometimes.

A more serious example is:

    find -name \*.jsp | sed 's/^/http:\/\/127.0.0.1/server/g' | xargs -n 1 wget

...will find all your jsp's, map them to your localhost webserver, and invoke a wget (fetch) on them. Viola, precompiled JSP's.

Another:

    for f in `find -name \*.jsp` ; do echo "==> $f" >> out.txt ; grep "TODO" $f >> out.txt ; done ...this searches JSP's for "TODO" lines and appends them all to a file with a header showing what file they came from (yeah, I know grep can do this, but it's an example. What if grep couldn't?) ...and finally...

( echo "These were the command line params"
    echo "---------"
    for f in $@ ; do
          echo "Param: $f"
    done ) | mail -s "List" you@you.com ...the parenthesis let your build up lists of things (like interestingly formatted text) and it gets returned as a chunk, ready to be passed on to some other shell processing function.

Shell scripting has saved me a lot of time in my life, which I am grateful for. :^)

--Robert

Re:pushd and popd (and other tricks) (Score:2)
by reidbold (55120) <rmiller@uoguelp h . ca> on Wednesday March 10, @03:22PM (#8524442)
(http://beadgame.org/)

set prompt = "%{^[[032;1m%}`whoami`%{^[[0m%} %c3 %B%#%b "

I don't think anything could be more clear.

[Oct 15, 2003] BASH with Debugger and Improved Debug Support and Error Handling

The Bash Debugger Project contains patched sources to BASH that enable better debugging support as well as improved error reporting. In addition, this project contains the most comprehensive source-code debugger for bash that has been written.

Since this project maintains as an open CVS development and encourages developers and ideas, the space could be also be used springboard for other experiments and additions to BASH. If you are interesting in contributing to this project, please contact rocky@panix.com.

However, if you are looking for the plain vanilla BASH, try here.

BASHDB Documentation Debugger documentation online. BASH Documentation Documentation including changes to support debugging
Screenshot 1 [breakpoint] A screenshot of bashdb in Emacs Screenshot 2 [backtrace] Another screenshot of bashdb in Emacs
Download Get the latest version here. Screenshot 3 [ddd] A screenshot of bashdb under DDD
CVS Browse the CVS Tree
Sourceforge The sourceforge.net project page.
Notes:
  • This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Some amount of grammar and spelling errors should be expected.
  • The site contain some broken links as it develops like a living tree... Please try to use Google, Open directory, etc. to find a replacement link (see HOWTO search the WEB for details). We would appreciate if you can mail us a correct link.
Google Search
Open directory

Research Index

[Jun 14, 2003] The latest and greatest ksh93  

Highly recommended as a replacement shell for Solaris and as an additional shell for Linux.
2003-04-22  BASE  * sol8.sun4 722124

[Nov 7,  2002] RE: bash 2.05b-7 and command line tab completion

I can't tell whether this bug (tab-completion adding a space when it is used for the first word after the prompt) is Cygwin-specific, or if it was added with bash 2.05. My two versions of bash running on Linux are 2.04. Neither of them have this bug. Does someone have another (non-Cygwin) bash 2.05 that can test this behavior?

> -----Original Message-----
> From: Eric Blake [mailto:ebb9@email.byu.edu]
> Sent: Thursday, November 07, 2002 10:25 AM
> To: cygwin@cygwin.com
> Subject: bash 2.05b-7 and command line tab completion
> 
> 
> I'm still having problems with tab completion in the latest bash:
> 
> $ bash --version
> GNU bash, version 2.05b.0(7)-release (i686-pc-cygwin)
> Copyright (C) 2002 Free Software Foundation, Inc.
> $ ll ~/jacks/jacks # I typed ll ~/ja[TAB]jacks
> -rwxr-xr-x    1 eblake   unknown       558 Jul 24 18:33 jacks*
> $ ~/jacks jacks # I typed ~/ja[TAB]jacks
> 
> I expected to get ~/jacks/jacks both times, but the bash is 
> inserting a space after ~/directory when it is the first (but not subsequent) 
> command line word.  However, /h[TAB]e[TAB]ja[TAB]jacks now 
> works, giving /home/eblake/jacks/jacks (and it hasn't always done so in 
> prior versions of bash).  So whatever was fixed to make /-based tab completion work 
> needs to also apply to ~-based tab completion.
> 
> -- 
> This signature intentionally left boring.
> 
> Eric Blake             ebb9@email.byu.edu
>    BYU student, free software programmer

[Mar 14, 2003] Corinna Vinschen - Updated bash-2.05b-9  I've updated the version of bash in the Cygwin distro to 2.05b-9.

This version uses Cygwin's access() function now for figuring out if a user may access a file instead of it's own function to do this. This should result in more reliable results of access tests in shell scripts when running under Cygwin 1.3.21 and later. To update your installation, click on the "Install Cygwin now" link on   the http://sources.redhat.com/cygwin web page.  This downloads setup.exe to your system.  The, run setup and answer all of the questions.

Continue...


Copyright © 1996-2009 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Site uses AdSense so you need to be aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

Disclaimer:

Last modified: August 15, 2009