cannot run file.sh in file1.sh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cannot run file.sh in file1.sh
# 1  
Old 02-03-2012
Data cannot run file.sh in file1.sh

Hi All,

I got a problem in executing block.sh in w.sh. In particular, I got some files as
w.sh, block.sh , blackip.db , b.txt in a chain process as below:

w.sh --call --> block.sh -->blackip.db--->b.txt <--iptables

Ok, here are code
w.sh
Quote:
#!/bin/bash
# 60 sec x 60 min x 23h
i=82800
while [ ${i} -gt 0 ]; do
w | grep load | awk '{print$1, $10, $11, $12, $13 }' >> /home/load
/webspace/www/html/block.sh
sleep 180
let i=$i-180
done
block.sh

Quote:
#!/bin/bash
LOGFILE="/webspace/www/html/blackip.db"
awk '{a[$1]++;next}END{for (i in a){if(a[i]>10){print i}}}' $LOGFILE > b.txt
BLOCKED_IP="/webspace/www/html/b.txt"
IPTABLES=`whereis iptables | awk '{print $2}'`
if [ -f $BLOCKED_IP ]; then
while read BLOCKED; do
$IPTABLES -A INPUT -i eth1 -s $BLOCKED -j DROP
$IPTABLES -A OUTPUT -o eth1 -d $BLOCKED -j DROP
done < $BLOCKED_IP
cat /dev/null > /webspace/www/html/blackip.db
cat /dev/null > /webspace/www/html/b.txt
fi
blackip.db is a file of ip collection
Quote:
1.1.1.1
2.2.2.2
1.1.1.1
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
3.3.3.3
b.txt contains ip of collection which is for iptables to drop

I normally can run ./block.sh and it is ok , but when i run ./w.sh it can not run block.sh.

Could somebody help me to solve this problem ?


Thanks in advance
# 2  
Old 02-04-2012
What is "w" here? Is it valid?
Code:
#!/bin/bash
# 60 sec x 60 min x 23h
i=82800
while [ ${i} -gt 0 ]
do
   w | grep load | awk '{print$1, $10, $11, $12, $13 }' >> /home/load
   /webspace/www/html/block.sh
   sleep 180
   let i=$i-180
done


You are populating "b.txt" in the current directory and then checking for the file existence in /webspace/www/html/b.txt.
Are they in the same directory?
Code:
#!/bin/bash
LOGFILE="/webspace/www/html/blackip.db"
awk '{a[$1]++;next}END{for (i in a){if(a[i]>10){print i}}}' $LOGFILE  > b.txt

BLOCKED_IP="/webspace/www/html/b.txt"
#IPTABLES=`whereis iptables | awk '{print $2}'`
#Better this way?
IPTABLES=`which iptables`

if [ -f $BLOCKED_IP ]
then
  while read BLOCKED
  do
      $IPTABLES -A INPUT -i eth1 -s $BLOCKED -j DROP
      $IPTABLES -A OUTPUT -o eth1 -d $BLOCKED -j DROP
  done < $BLOCKED_IP
  #What are you trying to do here? Emptying the file?
  #cat /dev/null > /webspace/www/html/blackip.db
  #cat /dev/null > /webspace/www/html/b.txt
  #Better?
  >/webspace/www/html/blackip.db;
  >/webspace/www/html/b.txt
fi

Put set -x in both the scripts and see what is wrong.

--ahamed

Last edited by ahamed101; 02-04-2012 at 05:05 AM..
# 3  
Old 02-04-2012
@ahamed101

Thank for your reply,

Yes, I am using CentOS 5.6 and command "w" is valid. iam using it for checking server load purpose.

b.txt, block.sh and blackip.db are stored in the same path /webspace/www/html/


There is no problem with execute ./block.sh but it doesn't work if call from w.sh

I though this could be clearly showed the full path of b.txt in block.sh . Let I try this and wait...

----------------

Ok as I though , the problem is exactly in the path of b.txt ..Should be clearly declared it. ^^,

Last edited by testcase; 02-04-2012 at 07:21 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to look up values in File 2 from File 1, & printingNth field of File1 based value of File2 $2

I have two files which are the output of a multiple choice vocab test (60 separate questions) from 104 people (there are some missing responses) and the question list. I have the item list in one file (File1) Item,Stimulus,Choice1,Choice2,Choice3,Choice4,Correct... (5 Replies)
Discussion started by: samonl
5 Replies

2. Shell Programming and Scripting

awk to search field2 in file2 using range of fields file1 and using match to another field in file1

I am trying to use awk to find all the $2 values in file2 which is ~30MB and tab-delimited, that are between $2 and $3 in file1 which is ~2GB and tab-delimited. I have just found out that I need to use $1 and $2 and $3 from file1 and $1 and $2of file2 must match $1 of file1 and be in the range... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. UNIX for Dummies Questions & Answers

Compare file1 and file2, print matching lines in same order as file1

I want to print only the lines in file2 that match file1, in the same order as they appear in file 1 file1 file2 desired output: I'm getting the lines to match awk 'FNR==NR {a++}; FNR!=NR && a' file1 file2 but they are in sorted order, which is not what I want: Can anyone... (4 Replies)
Discussion started by: pathunkathunk
4 Replies

4. Shell Programming and Scripting

Range Comparison Of Column Value in File1 with Other File

Hi, I have a file1 whose 17th column needs to be checked if it exists in between the values of column 2 & column 3 as mentioned in another file2. Output of the matched value to be put in separate file 3 & 4. File1: ... (10 Replies)
Discussion started by: siramitsharma
10 Replies

5. Shell Programming and Scripting

Pick a line in file 2 basing on array in file1

Dear friends, I have two files. One with all IDs(in a single field) . And another with data(of which say field 5 is ID). I want to create an array of IDs using first file and while reading second file if the ID appears in the array I need to print $0 else skip. After a long gap I am... (6 Replies)
Discussion started by: paresh n doshi
6 Replies

6. Shell Programming and Scripting

Deleting Multiple Lines in a File1 using critera found from File 2

Hi Everyone! I would like ask if there's a better way I can delete multiple lines in a file1 by collecting all criteria from file2. file1: a b c d e f file2: a e f The expected value will be: b (3 Replies)
Discussion started by: zzavilz
3 Replies

7. UNIX for Dummies Questions & Answers

if matching strings in file1 and file2, add column from file1 to file2

I have very limited coding skills but I'm wondering if someone could help me with this. There are many threads about matching strings in two files, but I have no idea how to add a column from one file to another based on a matching string. I'm looking to match column1 in file1 to the number... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

8. Shell Programming and Scripting

how to match a numers from file1 to file 2??Ps help me..

Hi firends, I need to write a program in perl for following task, I have a data like following numbers in file1.txt 1061338 1159781 1161717 1920355 1924487 2996733 3121872 3124510 I have to search the matching numbers in file2,my file2 is have a multiple columns like this ... (6 Replies)
Discussion started by: sureshraj
6 Replies

9. Solaris

cat file1 > file1

I have file1 with the contents this is file1 when i do cat file1 , the output is this is file1 when i run cat file1 > file1 , I receive the following message cat: input file1 is output (3 Replies)
Discussion started by: asalman.qazi
3 Replies

10. Shell Programming and Scripting

Read each word from File1 and search each file in file2

file1: has all words to be searched. 100007 200999 299997 File2: has all file names to be searched. C:\search1.txt C:\search2.txt C:\search3.txt C:\search4.txt Outfile: should have all found lines. Logic: Read each word in file1 and search each file in the list of File2; if the... (8 Replies)
Discussion started by: clem2610
8 Replies
Login or Register to Ask a Question