LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-03-2008, 12:22 AM   #1
Ashkan_s
Member
 
Registered: Jul 2008
Distribution: Fedora
Posts: 77

Rep: Reputation: 22
Post Shell script problem


Hi
If I write:
sh filepath1.sh start
at the beginning of file12 (with filepath2)
that the file1.sh (filepath1) was created before
whats the meaning of this?
 
Old 08-03-2008, 12:36 AM   #2
allez
Member
 
Registered: Jul 2008
Location: Russia/Siberia/Krasnoyarsk
Distribution: SuSE, CentOS, FreeBSD
Posts: 77

Rep: Reputation: 21
Excuse me, but it is slightly hard to understand your problem's description. Let's do this way:

1. Tell us, please, what do you have: show here contents of your scripts and their current output.
2. Then, tell us what do you need, that is, what output your scripts must produce.

Good luck!
 
Old 08-03-2008, 12:59 AM   #3
ehawk
Senior Member
 
Registered: Jul 2003
Posts: 1,257

Rep: Reputation: 48
yeah, we do not intend to seem unhelpful, but if you can explain a little more fully the problem you are experiencing, people will better understand how to help you. I tried to read and understand the content of you post, but it was difficult and a little frustrating, because we really do want to help you.
 
Old 08-03-2008, 02:09 AM   #4
Ashkan_s
Member
 
Registered: Jul 2008
Distribution: Fedora
Posts: 77

Original Poster
Rep: Reputation: 22
Post

OK
because it is a long code I did not write it before.
This firestarter firewall code.
This is the code of firestarter.sh
Code:
#!/bin/bash
#-----------( Firestarter Control Script )-----------#

# Load Configuration
source /etc/firestarter/configuration 2>&1

# --(Set program paths)--

IPT=`which iptables`
IFC=/sbin/ifconfig
MPB=/sbin/modprobe
LSM=/sbin/lsmod
RMM=/sbin/rmmod


# --(Extract Network Information)--

# External network interface data
IP=`/sbin/ifconfig $IF | grep inet | cut -d : -f 2 | cut -d \  -f 1`
MASK=`/sbin/ifconfig $IF | grep Mas | cut -d : -f 4`
BCAST=`/sbin/ifconfig $IF |grep Bcast: | cut -d : -f 3 | cut -d \  -f 1`
NET=$IP/$MASK

if [ "$NAT" = "on" ]; then
	# Internal network interface data
	INIP=`/sbin/ifconfig $INIF | grep inet | cut -d : -f 2 | cut -d \  -f 1`
	INMASK=`/sbin/ifconfig $INIF | grep Mas | cut -d : -f 4`
	INBCAST=`/sbin/ifconfig $INIF |grep Bcast: | cut -d : -f 3 | cut -d \  -f 1`
	INNET=$INIP/$INMASK
fi

if [ "$MASK" = "" -a "$1" != "stop" ]; then
	echo "External network device $IF is not ready. Aborting.."
	exit 2
fi

if [ "$NAT" = "on" ]; then
	if [ "$INMASK" = "" -a "$1" != "stop" ]; then
		echo "Internal network device $INIF is not ready. Aborting.."
		exit 3
	fi
fi


# --(Helper Functions)--

# Scrub data parameters before use
scrub_parameters () {
	target=`echo $target | sed 's/ //'g`
	port=`echo $port | sed 's/ //'g |  sed "s/-/:/"`
	ext_port=`echo $ext_port | sed 's/ //'g |  sed "s/-/:/"`
	int_port_dashed=`echo $int_port | sed 's/ //'g |  sed "s/:/-/"`
	int_port=`echo $int_port | sed 's/ //'g |  sed "s/-/:/"`
	if [ "$target" == "everyone" ]; then target=0/0
	else if [ "$target" == "firewall" ]; then target=$IP
	else if [ "$target" == "lan" ]; then target=$INNET
	fi fi fi
}


# --(Control Functions)--

# Create Firestarter lock file
lock_firestarter () {
	if [ -e /var/lock/subsys ]; then
		touch /var/lock/subsys/firestarter
	else
		touch /var/lock/firestarter
	fi
}

# Remove Firestarter lock file
unlock_firestarter () {
	if [ -e /var/lock/subsys ]; then

		rm -f /var/lock/subsys/firestarter
	else
		rm -f /var/lock/firestarter
	fi
}

# Start system DHCP server
start_dhcp_server () {
	if [ "$DHCP_DYNAMIC_DNS" = "on" ]; then
		NAMESERVER=
		# Load the DNS information into the dhcp configuration
		while read keyword value garbage
			do
			if [ "$keyword" = "nameserver" ]; then
				if [ "$NAMESERVER" = "" ]; then
					NAMESERVER="$value"
				else
					NAMESERVER="$NAMESERVER, $value"
				fi
			fi
			done < /etc/resolv.conf

		if [ "$NAMESERVER" != "" ]; then
			if [ -f /etc/dhcpd.conf ]; then
				sed "s/domain-name-servers.*$/domain-name-servers $NAMESERVER;/" /etc/dhcpd.conf > /etc/dhcpd.conf.tmp
				mv /etc/dhcpd.conf.tmp /etc/dhcpd.conf
			fi
			if [ -f /etc/dhcp3/dhcpd.conf ]; then
				sed "s/domain-name-servers.*$/domain-name-servers $NAMESERVER;/" /etc/dhcp3/dhcpd.conf > /etc/dhcp3/dhcpd.conf.tmp
				mv /etc/dhcp3/dhcpd.conf.tmp /etc/dhcp3/dhcpd.conf
			fi
		else
			echo -e "Warning: Could not determine new DNS settings for DHCP\nKeeping old configuration"
		fi
	fi

	if [ -e /etc/init.d/dhcpd ]; then
		/etc/init.d/dhcpd restart > /dev/null
	else
		/usr/sbin/dhcpd 2> /dev/null
	fi

	if [ $? -ne 0 ]; then
		echo Failed to start DHCP server
		exit 200
	fi
}

# Start the firewall, enforcing traffic policy
start_firewall () {
	lock_firestarter
	source /etc/firestarter/firewall 2>&1
	retval=$?
	if [ $retval -eq 0 ]; then
		echo "Firewall started"
	else
		echo "Firewall not started"
		unlock_firestarter
	exit $retval
fi
}

# Stop the firewall, traffic flows freely
stop_firewall () {
	$IPT -F
	$IPT -X
	$IPT -Z
	$IPT -P INPUT ACCEPT
	$IPT -P FORWARD ACCEPT
	$IPT -P OUTPUT ACCEPT
	$IPT -t mangle -F 2>/dev/null
	$IPT -t mangle -X 2>/dev/null
	$IPT -t mangle -Z 2>/dev/null
	$IPT -t nat -F 2>/dev/null
	$IPT -t nat -X 2>/dev/null
	$IPT -t nat -Z 2>/dev/null
	retval=$?
	if [ $retval -eq 0 ]; then
		unlock_firestarter
		echo "Firewall stopped"
	fi
	exit $retval
}

# Lock the firewall, blocking all traffic
lock_firewall () {
	$IPT -P INPUT DROP
	$IPT -P FORWARD DROP
	$IPT -P OUTPUT DROP
	$IPT -F;
	$IPT -X
	$IPT -Z
	retval=$?
	if [ $? -eq 0 ]; then
		echo "Firewall locked"
	fi
	exit $retval
}

# Report the status of the firewall
status () {
	if [ -e /var/lock/subsys/firestarter -o -e /var/lock/firestarter ]; then
		echo "Firestarter is running..."
	else
		echo "Firestarter is stopped"
	fi
}

case "$1" in
start)
	start_firewall
 	if [ "$NAT" = "on" -a "$DHCP_SERVER" = "on" ]; then
		start_dhcp_server
	fi
;;
stop)
	stop_firewall
;;
lock)
	lock_firewall
;;
status)
	status
;;
reload-inbound-policy)
	source /etc/firestarter/inbound/setup 2>&1
;;
reload-outbound-policy)
	source /etc/firestarter/outbound/setup 2>&1
;;
*)
	echo "usage: $0 {start|stop|lock|status}"
	exit 1
esac
exit 0

and this is (sh .../firestarter.sh start) written at the beginning of some files like:
/etc/ppp/ip-up.local

and I don't know what is this file.I can't find it.

Last edited by Ashkan_s; 08-03-2008 at 02:21 AM. Reason: better explaining
 
Old 08-03-2008, 03:47 AM   #5
allez
Member
 
Registered: Jul 2008
Location: Russia/Siberia/Krasnoyarsk
Distribution: SuSE, CentOS, FreeBSD
Posts: 77

Rep: Reputation: 21
/etc/ppp/ip-up.local is used to place miscelannious user commands for PPP connection. When you make a new connection, it is not bad idea to start firewall (or update its state) by running firestarter.sh.

Last edited by allez; 08-03-2008 at 03:49 AM.
 
Old 08-03-2008, 09:04 AM   #6
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 346

Rep: Reputation: 152Reputation: 152
If the problem can be restated as:-
"I have one file 'firestarter.sh' and I've been looking for a second file 'firestarter.sh start' but I can't find it."
Then:-
There isn't a second file; 'start' is the $1 parameter for the 'firestarter.sh' script, it's telling the script which job to do, it's not part of the filename.
$1 is tested to see if it equals 'start' in the case statement near the end of 'firestarter.sh'
Code:
case "$1" in
start)
        start_firewall
 
Old 08-03-2008, 10:27 AM   #7
Ashkan_s
Member
 
Registered: Jul 2008
Distribution: Fedora
Posts: 77

Original Poster
Rep: Reputation: 22
Hi
Thanks so much for your helps
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script problem Ashkan_s Linux - Software 3 07-27-2008 07:37 AM
shell script problem bondoq Linux - Newbie 6 07-03-2006 02:45 AM
problem with C shell script stoneman Programming 2 12-22-2005 08:39 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Shell script problem maringat Linux - Software 5 07-25-2005 05:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:44 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration