[问题]打开一个脚本时出现问题,请大家帮助

sh/bash/dash/ksh/zsh等Shell脚本
回复
unrealnut
帖子: 6
注册时间: 2008-06-03 22:37

[问题]打开一个脚本时出现问题,请大家帮助

#1

帖子 unrealnut » 2008-06-07 8:58

我是河南网通用户,DHCP+,通过wiki里介绍的方式上网,可是到了在shell窗口运行脚本的时候,出现 :

代码: 全选

/bin/sh: Can't open
我现在无法在ubuntu下上网。请问这是不是shell脚本的问题?如果是,该怎样解决?还有就是我用的是wubi安装,是不是和这个有关系?
头像
xiooli
帖子: 6956
注册时间: 2007-11-19 21:51
来自: 成都
联系:

#2

帖子 xiooli » 2008-06-07 9:36

贴出脚本代码
unrealnut
帖子: 6
注册时间: 2008-06-03 22:37

.

#3

帖子 unrealnut » 2008-06-07 10:26

我现在只能在win下上网,在win下打开脚本文件毫无格式可言……先贴出来试试吧

代码: 全选

#!/bin/sh

EXCUTE_NAME="racer"
X_NAME="race"

verify_system()
{
  #check if this is a linux platform, if not linux, alert and quit
  if [ `uname` != "Linux" ]; then
	echo "This process being available ONLY on Linux"
  	return 1
  fi

  #check if it's root, otherwise quit
  if [ `whoami` != "root" ]; then
  	echo "No more than root has previlege to run this process"
  	return 1
  fi
  #check size of log file
  if [ -f "ecou.log" ]; then
	FSIZE=`du -ks ecou.log | awk '{print $1}'`
	if [ $FSIZE -gt 1000 ]; then
		>ecou.log	#clear the log file
	fi
  else
             >ecou.log
  fi
  
  return 0
}

find_ecou()
{
   #FINDNUM=`ps -ef | grep "$EXCUTE_NAME" | grep -v grep | wc -l`
   FINDNUM=`pgrep -nx "$EXCUTE_NAME" | wc -l`
   if [ $FINDNUM -eq 0 ]; then
	return 1
   else
	return 0
   fi
}

start_ecou()
{ 
  if find_ecou
  then
	echo "The pocess is running"
	exit
  fi

  #to which interface link with Internet
  INTERNUM=`ifconfig -a | grep "HWaddr" | wc -l`
  if [ $INTERNUM -eq 0 ]; then
	echo "No net Interface can be found, may you type command such as insmod and ifup eth0 first"
	return 1
  fi

  #if more than ONE eth installed, have to select one
  CMPNUM=0
  if [ "$INTERNUM" -gt "$CMPNUM" ]; then
	ifconfig -a | grep "HWaddr" | awk '
	  BEGIN {
		i=0;
		printf("All names of your net interface installed\n");
		printf("-----------------------------------------\n");
	  }
	  {
		printf("\t%s\t%d\n", $1, i);
		i++;
	  }'
         echo -n "Input one name to hace access with Internet (eth0): "	
	 read INTERNAME
	 if [ ! $INTERNAME ]; then   #default name is eth0
		INTERNAME="eth0"
	 fi
	 #if the name input is correct or not
	 TMP_NUM=`ifconfig -a | grep "HWaddr" | grep "$INTERNAME" | wc -l`
	 if [ $TMP_NUM -eq 0 ]; then
		echo "You have input an invalid name of net interface"
		return 1
	 fi
  else
	INTERNAME=`ifconfig -a |grep "HWaddr" |	awk '{print $1}'` 
  fi
  echo "The name of interface is: " $INTERNAME

  #okey, we have got correct env & parameters to run this process
  #However, definitly necessary ini files as well as process file must be found 
  #in the same path
  if [ ! -f "racer.ini" ]; then
	echo "Warning: No relative file racer.ini found, re-creating"
	echo "Server1=218.29.0.227" >racer.ini
	echo "Server2=218.29.0.228" >>racer.ini
  fi

  if [ ! -f "$X_NAME" ]; then
	echo "Unable to find process to run, try re-install your process again!"
	return 1
  fi
  	
  if [ ! -x "$X_NAME" ]; then
	chmod +x $X_NAME
  fi
  
  if [ ! -L "$EXCUTE_NAME" ]; then
	ln -s $X_NAME $EXCUTE_NAME
  fi
  
  ./$EXCUTE_NAME $INTERNAME

  RETVAL=$?
  if [ ! $RETVAL -eq 0 ]; then
	echo "Failed to run the process"
  else
	echo "$EXCUTE_NAME has been started successfully"
  fi
  
  return 0
}

#for help info
usage()
{
	echo "Usage: $0 {[start]|[status]|[stop]}"	
}

#to stop ecou
stop_ecou()
{
    #ps -ef | grep "$EXCUTE_NAME" | grep -v grep | awk '{print $2}' | xargs kill -SIGINT 2>/dev/null
    pgrep -nx "$EXCUTE_NAME" | xargs kill -SIGINT 2>/dev/null
    FINDNUM=1
    while [ ! $FINDNUM -eq 0 ]
    do
    	#FINDNUM=`ps -ef | grep "$EXCUTE_NAME" | grep -v grep | wc -l`
    	FINDNUM=`pgrep -nx "$EXCUTE_NAME" | wc -l`
    	sleep 1
    done
    if [ $? -eq 0 ]; then
       	echo "The process has been halted successfully"
    else
       	echo "Failed to terminate the process OR the process is not running"
    fi
}

#to tell status
tell_status()
{
   #ps -ef | grep "$EXCUTE_NAME" | grep -v grep | awk '{print $2}' | xargs kill  -SIGUSR1 2>/dev/null
   pgrep -nx "$EXCUTE_NAME" | xargs kill  -SIGUSR1 2>/dev/null
   if [ $? -eq 0 ]; then
	return;
   else
	echo "No status returned for $EXCUTE_NAME"
   fi
}

#main
  PARAM_NUM=$#
  if [ ! $PARAM_NUM -eq 1 ]; then
    usage
    exit
  fi
  
  if [ -n $RACERC ]; then
      cd $RACERC
  fi

  if ! verify_system
  then
     exit
  fi

  case $1 in
	start) 	start_ecou;;
        status) tell_status;;
        stop) 	stop_ecou;;
	*)usage;;
  esac

上次由 unrealnut 在 2008-06-07 10:29,总共编辑 3 次。
unrealnut
帖子: 6
注册时间: 2008-06-03 22:37

补充

#4

帖子 unrealnut » 2008-06-07 10:27

还有根据wiki中提到的,将脚本开始时的

代码: 全选

#!/bin/sh 
EXCUTE_NAME="racer" 
X_NAME="race"
替换为

代码: 全选

#!/bin/sh 
LANG=en_US 
export RACERC=/opt/racer 
export PATH=$PATH:/racer 
EXCUTE_NAME="racer" 
X_NAME="race" 
回复