HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Modify the script
Operating System - Linux
1828038
Members
1979
Online
109973
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2005 02:50 AM
01-05-2005 02:50 AM
Sorry to ask the innocent question , I have the below script that run very fine at unx can't fail in linux box , could suggest how can I modify it to make it also work at linux box , very thanks if anyone can help .
the script:
#!/bin/sh
PATH=$PATH:/usr/bin:/usr/sbin:/usr/contrib/bin
TIMEOUT=40
EXCEPTIONLIST=~/etc/exception.lst
touch $EXCEPTIONLIST
kill_pid()
{
PID=$1
kill -9 $PID
}
echo "User:Activity:PID:Status"
who -u | while read line
do
time=$(echo $line | awk '{print $6}')
pid=$(echo $line | awk '{print $7}')
user=$(echo $line | awk '{print $1}')
grep -q "^${user}:" $EXCEPTIONLIST
if [ $? != 0 ]
then
if [ "$time" = "old" ]
then
(( time = $TIMEOUT + 1 ))
else
echo $time |grep -q "\."
if [ $? != 0 ]
then
time=$(echo $time|awk '{FS=":";print $1*60+$2}')
else
time=0
fi
fi
fi
#echo $time
if [ $time -gt $TIMEOUT ]
then
echo "$user:$time:$pid:Killed"
# Uncomment to do kill that PID
kill_pid $pid
else
echo "$user:$time:$pid:Untouched"
fi
done
______________________________________________________
the error is
./kill_idle: line 38: [: 00:03: integer expression expected , where line 38 is "if [ $time -gt $TIMEOUT ]"
the script:
#!/bin/sh
PATH=$PATH:/usr/bin:/usr/sbin:/usr/contrib/bin
TIMEOUT=40
EXCEPTIONLIST=~/etc/exception.lst
touch $EXCEPTIONLIST
kill_pid()
{
PID=$1
kill -9 $PID
}
echo "User:Activity:PID:Status"
who -u | while read line
do
time=$(echo $line | awk '{print $6}')
pid=$(echo $line | awk '{print $7}')
user=$(echo $line | awk '{print $1}')
grep -q "^${user}:" $EXCEPTIONLIST
if [ $? != 0 ]
then
if [ "$time" = "old" ]
then
(( time = $TIMEOUT + 1 ))
else
echo $time |grep -q "\."
if [ $? != 0 ]
then
time=$(echo $time|awk '{FS=":";print $1*60+$2}')
else
time=0
fi
fi
fi
#echo $time
if [ $time -gt $TIMEOUT ]
then
echo "$user:$time:$pid:Killed"
# Uncomment to do kill that PID
kill_pid $pid
else
echo "$user:$time:$pid:Untouched"
fi
done
______________________________________________________
the error is
./kill_idle: line 38: [: 00:03: integer expression expected , where line 38 is "if [ $time -gt $TIMEOUT ]"
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2005 03:23 AM
01-05-2005 03:23 AM
Re: Modify the script
You can replace -gt with > like below:
old: "if [ $time -gt $TIMEOUT ]"
new: "if [ $time > $TIMEOUT ]"
Chris
old: "if [ $time -gt $TIMEOUT ]"
new: "if [ $time > $TIMEOUT ]"
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2005 03:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2005 03:37 AM
01-05-2005 03:37 AM
Re: Modify the script
Sorry, ignore my previous reply. It was wrong.
One way to fix it is to declare TIMEOUT as an integer in the beginning like this.
typeset -i TIMEOUT
TIMEOUT=40
Chris
One way to fix it is to declare TIMEOUT as an integer in the beginning like this.
typeset -i TIMEOUT
TIMEOUT=40
Chris
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP