Transfer one or more file(s) in a directory or directory hierarchy to a set of different directory's on one or more other servers. You have the choice of "IN script" parameters to CLI options, configuration via config file(s) or finaly completion via a shell. I don't need secure transfers at this time... but they may follow, feel free to implement it yourself and let me know.
The script is used to download the Daily Static Commic Strip of the User Friendly site by Illiad, via a proxy that requires authentication. The result of running this script is a gif image in the current directory with the name : "uftoday.gif"
C:\>copy con grep
for ( <STDIN> ) {print $_ if $_ =~ /@ARGV/ ;};
^Z
1 file(s) copied.
C:\>dir | perl grep <filter_string>
note: you always need to use "perl" or the ".pl" extention to execute perl scripts on Winblows machines!
# This is a lame attempt to wrap long lines to max.70 characters, they don't even filter emty lines!
# Create a directory and all unexisting directorys inbetween
perl -e '
@dirs=split "/","$ARGV[0]";
shift @dirs;
foreach $dir ( @dirs ) {
$makedir=$makedir."/$dir";
mkdir $makedir,0750 if ( not -e $makedir );
}
' $MAKEFULLPATH
"Kinda long to remember but i use it in shell scripts as a function."
# Get this cli script in vi for easy editing in memory using ksh!
[esc] + [v]
# Need to type a LineFeed (^J) in Korn shell?
[ctrl] + [v], [ctrl] + [j]
# Remove top line of a command:
df | tail +2 # kind of a side effect
df | sed '1d'
# Adding numbers in column layouts using awk:
ipcs -m -b | sed '1,3d' | awk '{SIZE+=$7} END {print SIZE}'
# Handy shell loops for the command line:
$ls -s1 | while read ss ff
>do
>print "size $ss - name and type \c"
>file $ff
>done
$while read LINE
>do
>echo "$LINE"
>done </tmp/file
$for ff in * # You can also use backtics for somme subshell output.
>do
>file $ff
>done
$while `sleep 5` # My favorite, instand, monitor.
>do
>clear
>df
>done
# You switch logs at night and quickly need yesterdays file?
ls -tr |tail -2|head -1
# Like to use find and grep in configs? Notice, there is a difference...
find /etc -type f -exec grep "string" {} \;
find /etc -type f -print | xargs grep "string" # In my favorite, you also get the filname.
# Howto use cat as an editor?
cat << EOF >> /tmp/file.out # Add everything after this line to file.out until the EOF string.
somme crappy text
EOF
# Determining the filesystem types of those partitions?
file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10}
# How do i feed the ex editor in vi a newline?
:%s/sommestr/sommestr^M/g
where ^M is generated by typing Ctrl-V or by Ctrl-V Ctrl-M, and
:set list
will show the EOL (reverse this with :set nolist), you will see $ as end of line via '\n', and ^M via '\r'. The sequence "[ctrl v][enter]" gives you UNIX style end of line, while "[ctrl v][ctrl m]" gives you the carriage return portion of DOS style EOL. A ^M all by itself is a Mac style EOL. So in the above, maybe you want to use [ctrl v][enter] rather than [ctrl v][ctrl m].
# How do i log everything to a file in a script?
Put this in the beginning of the script, it will capture all output and errors and your script will stay readable!
$exec >>/tmp/logfile 2>&1
Notification:
Somme charakters of the code in this page can be displayed wrongly,
do cross link the displayed code with html source to be shure.
And PLEASE notify me if you find somme of these abnormality's!
Last update: 15 Apr. 2003 by W. Van Hooste
| Top