|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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' |
|
#3
|
|||
|
|||
|
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() { "\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 "\n" >$FICHIER_LG 2>&1 |
![]() |
| Viewing: Web Development Archives > FAQs > Unix/Linux > Simplifying the script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|