![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| forcefully throwing error : unix script | dr46014 | UNIX for Dummies Questions & Answers | 1 | 10-01-2008 04:42 AM |
| awk Shell Script error : "Syntax Error : `Split' unexpected | Herry | UNIX for Dummies Questions & Answers | 2 | 03-17-2008 11:16 AM |
| Error while trying to fire a PL/SQL thro Unix Script | dharmesht | Shell Programming and Scripting | 5 | 12-11-2003 10:10 AM |
| UNIX error log | eysheikah | Security | 3 | 05-31-2003 09:21 AM |
| SCO UNIX error 6, HELP | PBNOSGT | UNIX for Dummies Questions & Answers | 0 | 02-01-2002 11:46 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Error in Unix Script
Hi! Following is the script to find the number of users and the total space consumed by them in the directory But I am getting few errors Pls help me Code:
data=`ls -lt $1 |tr -t [' '] ['\t']|tr -s '\t'|cut -f3,5`
count=0
flag=1
sum=0
users_flag=1
check=0
declare -a users
for a in $data
do
if [ $users_flag -eq 1 ]
then
for ((i = 0; $i <= count; $i++))
do
if [ $a = ${users[$count]} ]
then
flag=0
break
fi
done
if [ $flag -eq 1 ]
then
users[$count]=$a
count=expr`$count + 1`
echo $a >> userdata
fi
users_flag=0
else
if [ $flag -eq 1 ]
then
for b in $data
do
if [ $check -eq 0 ]
then
if [ $b = $a ]
then
check=1
fi
else
sum=`expr $sum + $b`
check=0
fi
done
fi
fi
done
Errors are q3: 7: declare: not found q3: 9: Syntax error: word unexpected (expecting "do") Last edited by joyrules; 03-18-2009 at 10:39 AM.. Reason: Formatted script |
|
||||
|
Agin Script Formatted
Code:
data=`ls -lt $1 |tr -t [' '] ['\t']|tr -s '\t'|cut -f3,5`
count=0
flag=1
sum=0
users_flag=1
check=0
declare -a users
for a in $data
do
if [ $users_flag -eq 1 ]
then
for ((i = 0; $i <= count; $i++))
do
if [ $a = ${users[$count]} ]
then
flag=0
break
fi
done
if [ $flag -eq 1 ]
then
users[$count]=$a
count=expr`$count + 1`
echo $a >> userdata
fi
users_flag=0
else
if [ $flag -eq 1 ]
then
for b in $data
do
if [ $check -eq 0 ]
then
if [ $b = $a ]
then
check=1
fi
else
sum=`expr $sum + $b`
check=0
fi
done
fi
fi
done
|
|
||||
|
What version of unix / linux ?
uname -a Which shell? Is this "sh", "ksh", "bash" or what? echo $SHELL Please show an example of what the output of the script should look like and state whether you count directory sizes as well as file sizes towards the per-user total. Please state whether there are subdirectories in the directory you wish to analyse. |
|
||||
|
Hi Joyeg.... Just try this out: Code:
#!/bin/bash
declare -a name_arr
declare -a size_arr
i=0
for files in `ls`
do
name=`ls -l $files | awk '{print $3}'`
size=`ls -l $files | awk '{print $5}'`
if [ $i -eq 0 ]
then
name_arr[$i]=`echo $name`
size_arr[$i]=`echo $size`
i=`expr $i + 1`
else
j=0
while [ $j -lt $i ]
do
if [ "${name_arr[$j]}" = "$name" ]
then
size_arr[$j]=`expr ${size_arr[$j]} + $size`
break
else
name_arr[$i]=`echo $name`
size_arr[$i]=`echo $size`
i=`expr $i + 1`
fi
j=`expr $j + 1`
done
fi
done
j=0
while [ $j -lt $i ]
do
echo "${name_arr[$j]} : ${size_arr[$j]}"
j=`expr $j + 1`
done
Lemme know incase of any problem Also, for your declare error, try to run your script in bash shell. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|