Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

execute script and delete himself after success

Posted on 2006-07-08
10
292 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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 200 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

861 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