[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

execute script and delete himself after success

Posted on 2006-07-08
10
Medium Priority
?
303 Views
Last Modified: 2013-12-16
i want to exexute a schript from a folder and then delete this a take the next entry from the folder.

i have a folder with a lot of script creted by '' split -l10  fillist" command.
so i have a lot file with names are starting with xaa and goes x**
all files are executeable.
if have a jobvariable $my_jobs.

if $my_jobs=0 then
'call the first file in my exec-folder
if
0
Comment
Question by:ebertsys
  • 5
  • 5
10 Comments
 
LVL 22

Expert Comment

by:pjedmond
ID: 17064323
'call the first file in my exec-folder only
---------------------------------------------------------X8--------------
MYDIR=/home/me/scripts

MYFILE in `ls | grep -e ^x | grep -e ^x`
exec ${MYFILE}
rm -Rf ${MYFILE}
---------------------------------------------------------X8--------------


...or 'call the files starting with an x file in my exec-folder:
---------------------------------------------------------X8--------------
MYDIR=/home/me/scripts
cd $MYDIR

        for MYFILE in `ls | grep -e ^x` ; do
            exec ${MYFILE}
            rm -Rf ${MYFILE}
        done

---------------------------------------------------------X8--------------
(   (()
(`-' _\
 ''  ''



0
 
LVL 22

Expert Comment

by:pjedmond
ID: 17064329
Ooops - need to change into the correct directory first!

'call the first file in my exec-folder only
---------------------------------------------------------X8--------------
MYDIR=/home/me/scripts
cd $MYDIR
MYFILE in `ls | grep -e ^x | grep -e ^x`
exec ${MYFILE}
rm -Rf ${MYFILE}
---------------------------------------------------------X8--------------
(   (()
(`-' _\
 ''  ''
0
 

Author Comment

by:ebertsys
ID: 17064410
sorry i'm a linux newbie..:)

myjobs=`gdsjob -l |grep -c 0                             # give a count of jobrows..
 for MYFILE in `ls | grep -e ^x` ; do
if $myjobs=0 ;then                                            #when no jobs there run script
            exec ${MYFILE}
            rm -Rf ${MYFILE}
if
        done


when i use it in this way i get an syntax error unexpeted token if   ??


0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:ebertsys
ID: 17064427
it's wrong..
what i want...
if the joblist is 0 then

the first file should be executet
and then delete

else
exit script.

end if

the mainscript i will call with an watch -n60
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 17064518
In which case:

insert this one into your script (sorry messed up the cut and paste last time:

'call the first file in my exec-folder only, and then delete it
---------------------------------------------------------X8--------------
MYDIR=/home/me/scripts
cd $MYDIR
MYFILE in `ls | grep -e ^x | sed -e q`      #Note the sed command rather than the grep - this takes the first file only
exec ${MYFILE}
rm -Rf ${MYFILE}
---------------------------------------------------------X8--------------
(   (()
(`-' _\
 ''  ''
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 17064527
Comments and insertions on your script:

----8X-----------
MYDIR=/home/me/scripts                                   #Need to change into the correct scripts directory for                
cd $MYDIR                                                         #the ls to work correctly.
myjobs=`gdsjob -l |grep -c 0                             # give a count of jobrows..
 for MYFILE in `ls | grep -e ^x | sed -e q` ; do                   #added sed -e q to take the first only
if $myjobs=0 ;then                                            #when no jobs there run script
            exec ${MYFILE}
            rm -Rf ${MYFILE}
end if              #<---------------------------------------------- end if perhaps;)..hence unexpected token!
        done
----8X-----------

(   (()
(`-' _\
 ''  ''
0
 
LVL 22

Accepted Solution

by:
pjedmond earned 600 total points
ID: 17064538
Try again - You've got a number of inconsistencies using 'different shells', combined with a few syntax errors from me;) Therefore I will use Bash:

Comments and insertions on your script:

----8X-----------
#!/bin/bash
MYDIR=/home/me/scripts                                   #Need to change into the correct scripts directory for                
cd $MYDIR                                                         #the ls to work correctly.
myjobs=`gdsjob -l |grep -c 0`                           # give a count of jobrows..
MYFILE = `ls | grep -e ^x | sed -e q` ; do                   #added sed -e q to take the first only
if  [ "$myjobs" = "0" ]; then                                            #when no jobs there run script
            exec ${MYFILE}
            rm -Rf ${MYFILE}
fi              #<---------------------------------------------- fi perhaps;)..hence unexpected token!
                                                                               #if else fi for bash
----8X-----------

http://www.faqs.org/docs/Linux-HOWTO/Bash-Prog-Intro-HOWTO.html#ss6.3

for the structure of conditionals in bash.

(   (()
(`-' _\
 ''  ''
0
 

Author Comment

by:ebertsys
ID: 17064598
i forgott the do in the if line and know i take the if row in remarks and it look as it should
i get an xab back what is the first script in the DIR.
but on exec ${myfile}             #the { and not (
i get an 'line 8 exec:xab:not found
mybe permissions?
----8X-----------
#!/bin/bash
myjobs=`gdsjob -l |grep -c 0`                             # give a count of jobrows..
 for MYFILE in `ls | grep -e ^x | sed -e q` ; do                   #added sed -e q to take the first only-----it's okay
#if $myjobs=0 ;then                                            #when no jobs there run script
            exec ${MYFILE}
            rm -Rf ${MYFILE}
#fi
done
----8X-----------

0
 

Author Comment

by:ebertsys
ID: 17064603
no it was the complite path
0
 

Author Comment

by:ebertsys
ID: 17064606
please ...at last ...what is wrong with my if...then...else....you know i'm old(50) stupid windows user:)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question