linux脚本接受输入,Shell脚本帮助 – 接受输入并在BackGround中运行?

我有一个

shell脚本,在第一行中我要求用户输入他们希望脚本运行的分钟数:

#!/usr/bin/ksh

echo "How long do you want the script to run for in minutes?:\c"

read scriptduration

loopcnt=0

interval=1

date2=$(date +%H:%M%S)

(( intervalsec = $interval * 1 ))

totalmin=${1:-$scriptduration}

(( loopmax = ${totalmin} * 60 ))

ofile=/home2/s499929/test.log

echo "$date2 total runtime is $totalmin minutes at 2 sec intervals"

while(( $loopmax > $loopcnt ))

do

date1=$(date +%H:%M:%S)

pid=`/usr/local/bin/lsof | grep 16752 | grep LISTEN |awk '{print $2}'` > /dev/null 2>&1

count=$(netstat -an|grep 16752|grep ESTABLISHED|wc -l| sed "s/ //g")

process=$(ps -ef | grep $pid | wc -l | sed "s/ //g")

port=$(netstat -an | grep 16752 | grep LISTEN | wc -l| sed "s/ //g")

echo "$date1 activeTCPcount:$count activePID:$pid activePIDcount=$process listen=$port" >> ${ofile}

sleep $intervalsec

(( loopcnt = loopcnt + 1 ))

done

如果我手动输入数值,它的效果很好.但如果我想运行3个小时,我需要启动脚本以在后台运行.

我试过运行./scriptname&我明白了

$How long do you want the test to run for in minutes:360

ksh: 360: not found.

[2] + Stopped (SIGTTIN) ./test.sh &

脚本死了.这是可能的,关于我如何接受这一个输入然后在后台运行的任何建议?谢谢!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值