Unix/Linux
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives FAQs Unix/Linux

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old June 30th, 2008, 10:49 AM
Ed Morton
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Simplifying the script



6/30/2008 9:59 AM, paul wrote:
Hello,
i have a basic question, i've made a ksh script under aix 5.3
I'd like to have only one line for the following two lines
print " rm -rf $DUMPREPDEST/$BASEDEST" >$FICHIER_LG
rm -rf $DUMPREPDEST/$BASEDEST >$FICHIER_LG 2>&1

Create a function that prints it's arguments to the log file, then evals the
arguments redirecting the results to the log file. Call that function for each
command you want to execute. Something like this:

$ function doit() { printf " %s\n" "$1"; eval "$1"; } >"$FICHIER_LG"
$ doit 'echo "hello"'
$ cat "$FICHIER_LG"
echo "hello"
hello

Regards,

Ed.


Reply With Quote
  #2  
Old June 30th, 2008, 10:49 AM
Icarus Sparry
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Simplifying the script

Mon, 30 Jun 2008 16:59:02 +0200, paul wrote:

Hello,
i have a basic question, i've made a ksh script under aix 5.3 I'd like
to have only one line for the following two lines
print " rm -rf $DUMPREPDEST/$BASEDEST" >$FICHIER_LG
rm -rf $DUMPREPDEST/$BASEDEST >$FICHIER_LG 2>&1
>

and i don't want to use echo ' ' | tee | ksh >$FICHIER_LG 2>&1
>

Here an example of a procedure, you see it's very verbose and it's
difficult to read and maintain.
>
>

Thanks for any advices
>


Since from your example you want everything to go to a logfile, you can
start off the script with

exec $FICHIER_LG 2>&1

and remove all the ">$FICHIER_LG" and ">$FICHIER_LG 2>&1" from the
individual lines.

You could then consider writing a function like

x(){
printf -- " %s\n" "$*"
eval "$@"
}

if you have control over all the inputs. Use it like

x 'mkdir -p $DUMPREST/$BASEDEST'

Reply With Quote
  #3  
Old June 30th, 2008, 10:49 AM
paul
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Simplifying the script

Hello,
i have a basic question, i've made a ksh script under aix 5.3
I'd like to have only one line for the following two lines
print " rm -rf $DUMPREPDEST/$BASEDEST" >$FICHIER_LG
rm -rf $DUMPREPDEST/$BASEDEST >$FICHIER_LG 2>&1

and i don't want to use echo ' ' | tee | ksh >$FICHIER_LG 2>&1

Here an example of a procedure, you see it's very verbose and it's difficult
to read and maintain.


Thanks for any advices


# Suppression/C des pour les backups/restos

supCreateRep()
{

print
"\n\n"
>$FICHIER_LG

print "`date '+%m/%d/%y'` `date '+%H:%M:%S'` Debut Suppression/Creation des
repertoires necessaires pour les backups/restos\n" >$FICHIER_LG

cd $DUMPREPDEST
# on s'assure qu'on est pas a la racine
if [ "`pwd`" != "/" ]
then
print " rm -rf $DUMPREPDEST/$BASEDEST" >$FICHIER_LG
rm -rf $DUMPREPDEST/$BASEDEST >$FICHIER_LG 2>&1

print " mkdir -p $DUMPREPDEST/$BASEDEST" >$FICHIER_LG
mkdir -p $DUMPREPDEST/$BASEDEST >$FICHIER_LG 2>&1

print " ssh $USERSURCE@$SERVERSURCE rm -rf $DUMPREPSURCE/$BASEDEST"
>$FICHIER_LG

ssh $USERSURCE@$SERVERSURCE "rm -rf $DUMPREPSURCE/$BASEDEST" >>
$FICHIER_LG 2>&1

print " ssh $USERSURCE@$SERVERSURCE mkdir -p
$DUMPREPSURCE/$BASEDEST" >$FICHIER_LG
ssh $USERSURCE@$SERVERSURCE "mkdir -p $DUMPREPSURCE/$BASEDEST" >>
$FICHIER_LG 2>&1

else
print "\nLa variable DUMPREP n'est pas correcte" >$FICHIER_LG
exit
fi

print "\n`date '+%m/%d/%y'` `date '+%H:%M:%S'` Fin Suppression/Creation des
repertoires necessaires pour les backups/restos" >$FICHIER_LG
print
"\n"
>$FICHIER_LG 2>&1





Reply With Quote
Reply

Viewing: Web Development Archives FAQs Unix/Linux > Simplifying the script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT