Click to See Complete Forum and Search --> : Newbie with Scripting
Scoobyfubar
12-04-2002, 04:58 PM
Hi all, I just started scripting and I am currently taking a course and I am stuck on a shell scripting question,, I am not looking for the answer just a shove in the right direction and maybe more clarification on this.
I have a script I have to edit to do certain things:
#!/bin/bash2
count=1
i=1
if [$i -1e $count]
then
item[$count]=a+$i
echo item[$count] "=" ${item[count]}
i=i+1
fi
1. I have to search the entire file system for blank files I created (ie:1,2,3,ect) that correspond to 1 through $1 and when I find a match I have to copy the name of the file to the file # that matched,,if none are found I have to send a text message to the numbered file. And to top it off I have to add information about when the script was run at the end of each file.
any help on this would be great!
Scoobyfubar
Rüpel
12-04-2002, 05:33 PM
hi,
i write a PM in german. maybe we can get things a little bit clearer in native language ;)
Rüpel
12-05-2002, 03:52 AM
Originally posted by Scoobyfubar
1. I have to search the entire file system for blank files I created
what is a "blank" file? the entire filesystem? sure? or the active directory only?
(ie:1,2,3,ect) that correspond to 1 through $1
i don't get the sense
and when I find a match I have to copy the name of the file to the file # that matched
the name of the blank file into the file itself?
if none are found I have to send a text message to the numbered file.
what is the numbered file?
And to top it off I have to add information about when the script was run at the end of each file.
date >> filename
sorry. if i didn't understand everything due to my limited english-knowledge, but the PMs discovered that english might be the better platform, so i'm the limiting factor here language-wise... :rolleyes:
Scoobyfubar
12-05-2002, 05:43 AM
My problem to,,, I dont understand the question and I am also new to scripting,,,,I sent you a pm with I think better clarification.
I think we can tackle this..
is this the learning curve? lol
I think all live threw this
Rüpel
12-05-2002, 07:22 AM
hmm. lets keep it public. maybe someone else is interested in the problem.
my first try is:
#!/bin/bash
echo -n "searching..."
find / -type f -regex '^.*[0-9]+[^/]*$' > result 2> searcherrors
echo "done"
for i in 1 2 3 4 5 6 7 8 9
do
grep "^.*$i[^/]*" result > ~/files/$i
date >> ~/files/$i
done
it searches your entire filesystem for files containing any digit and saves them all into the local file result. after that the result is split into the file ~/files/1 to ~/files/9
as i said: the first try. ;)
Scoobyfubar
12-05-2002, 09:35 AM
ok I think we are getting somewhere!
I am going to add to your program and I will add notes.
#!/bin/bash2 #(bash2)
declare -i #(so the intreger variables are seen properly)
echo -n "searching..."
find / -type f -regex '^.*[0-9]+[^/]*$' > result 2> searcherrors
#find "files 1-$1 if "found" copy "name of file into file number"
echo "done"
for i in 1 2 3 4 5 6 7 8 9
do
grep "^.*$i[^/]*" result > ~/files/$i
date >> ~/files/$i
done #(fi?
How would you output "echo" NO FILE FOUND MATCHING NUMBER...if it does not find the files for the number?
maybe they want us to use arrays ie: echo ${variable[5]}or variable[n] =value. Meanining the files 1,2,3,4 that correspond to 1-$1 ?