Solved

execute script and delete himself after success

Posted on 2006-07-08
10
285 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
 

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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Encrypted Laptop running Linux 3 79
Problem logging tar errors 11 35
Ubuntu 16.04 AMD video card driver issues 20 104
linux ssh 4 29
rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now