LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 01-08-2007, 09:51 AM   #1
jukemann
LQ Newbie
 
Registered: Jan 2007
Posts: 1

Rep: Reputation: 0
need run-parts run in reverse.


I understand that run-parts run scripts in a directory one after another in abc order. I'm not very good with bash but I need a script to run in reverse order instead.

This is the script for run-parts any help would be greatly appreciated.
Quote:
# cat /usr/bin/run-parts
#!/bin/bash

# run-parts - concept taken from Debian

# keep going when something fails
set +e

if [ $# -lt 1 ]; then
echo "Usage: run-parts <dir>"
exit 1
fi

if [ ! -d $1 ]; then
echo "Not a directory: $1"
exit 1
fi

# Ignore *~ and *, scripts
for i in $1/*[^~,] ; do
[ -d $i ] && continue
# Don't run *.{rpmsave,rpmorig,rpmnew,swp} scripts
[ "${i%.rpmsave}" != "${i}" ] && continue
[ "${i%.rpmorig}" != "${i}" ] && continue
[ "${i%.rpmnew}" != "${i}" ] && continue
[ "${i%.swp}" != "${i}" ] && continue
[ "${i%,v}" != "${i}" ] && continue

if [ -x $i ]; then
$i 2>&1 | awk -v "progname=$i" \
'progname {
print progname ":\n"
progname="";
}
{ print; }'
fi
done

exit 0
 
Old 01-08-2007, 10:08 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,017
Blog Entries: 54

Rep: Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764
Easier instead would be to rename your current jobs in reverse order 0 to 9, a to z. Added advantage is it doesn't break compat with run-parts.
 
Old 01-08-2007, 10:21 AM   #3
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,147

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Try changing the line for i in $1/*[^~,] ; do to

for i in `echo $1/*[^~,] | sort -dr` ; do

or

for i in `ls -1r | grep -r '[^~,]$'` ; do

See man sort and man ls for more details about those commands.

You might also want to look at the find command as an easier way to do what you want.

And, of course, the gawk language, since the whole of the script you displayed could be accomplished in a gawk program, with even more flexability.

Notes:
1) I've not tried either of these, although I think that they'll work.
2) Note the use of the back-quotes to tell bash to use the command output.

Last edited by PTrenholme; 01-08-2007 at 10:23 AM.
 
Old 01-08-2007, 09:31 PM   #4
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,147

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Quote:
Originally Posted by unSpawn
Easier instead would be to rename your current jobs in reverse order 0 to 9, a to z. Added advantage is it doesn't break compat with run-parts.
Or use the method used by some distributions to specify the order in which system services should be started. That is, put the scripts in a directory (or leave them scattered all over the place), and create another directory with symbolic links to the scripts to be run using names (usually starting with a number are a single letter and a number with leading zeros) that, when ordered, specify the proper sequence.

For example, on Fedora the service startup scripts are kept in /etc/init.d/, and the links to those scripts -- for each run level -- are kept in /etc/rc.d/rc[0-6].d. Fedora actually uses two different single letter prefixes -- "K" for "kernel" services (loaded before the kernel is started) and "S" for "system" services (loaded after the kernel is started), but that's probably an irrelevant detail.

Last edited by PTrenholme; 01-09-2007 at 09:02 PM.
 
Old 01-10-2007, 09:41 AM   #5
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,147

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Another thought: Create a list of the scripts you wish to run, and then run them in the order in which they're listed in the file.

For example, replace the line for i in $1/*[^~,];do with
Code:
if [ $# -gt 1 -a -r "$2" ]; then
  list=$2;
  rm="no";
else
  list=`mktemp -t list.XXXX`;
  rm="yes";
  echo $1/*[^~,] > $list;
fi
for i in `cat $list`; do
.
.
.
done
[ "$rm" = "yes" ] && rm $list;
The thing with Linux is, there's always more than one way to solve a problem. And it's fun thinking up new ways.

Last edited by PTrenholme; 01-10-2007 at 09:44 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What does the run-parts mean in crontab? mTorbin Linux - Newbie 15 04-27-2012 03:53 PM
run-parts gives error on bash script ChoKamir Programming 6 01-31-2012 01:36 AM
run-parts not reading all possible scripts merana Debian 6 12-28-2005 09:40 AM
crontab and run-parts gavinbeatty Slackware 4 09-13-2005 06:56 PM
Cannot get NVIDIA-Linux-x86_64-1.0-6629-pkg2.run to run properly doctorwebbox Linux - Hardware 0 02-06-2005 06:18 AM


All times are GMT -5. The time now is 06:58 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration