Hi,
When I try to run this script I keep getting the error "/quota.sh: fgrep 5162 /home/nasadmin/quotas_michel/userlist.txt: No such file or directory" but when i run this command typed in I do get the correct output. Can somebody help me?
This is the script:
# Omgevingsvariabelen instellen
#-------------------------------------------------------------------------------------------
NAS_DB=/nas
NAS_BIN=${NAS_DB}/bin
NAS_SBIN=${NAS_DB}/sbin
PATH=${PATH}:${NAS_BIN}:${NAS_SBIN}
export NAS_DB PATH
REPORT_ROOT=/home/nasadmin/quotas_michel
# datum ophalen
#-------------------------------------------------------------------------------------------
REPORT_DATE=`date +%D,%T`
# Lijst met gebruikers ophalen
#-------------------------------------------------------------------------------------------
cat /nas/cifs/usrmapperV3/autoumupload/server_2_newpasswd | cut -d\: -f1,3,5 > userlist.txt
# Lijsten genereren van filesystemen waar quota's op staan
#-------------------------------------------------------------------------------------------
nas_quotas -user -report -fs user1 > user1.txt
cat user1.txt | while read LINE
do
USERID=`echo $LINE | cut -f 2 -d\| | cut -d# -f2`
USED=`echo $LINE | cut -f3 -d\|`
SOFT=`echo $LINE | cut -f4 -d\|`
HARD=`echo $LINE | cut -f5 -d\|`
UTEMP=`"fgrep $USERID $REPORT_ROOT/userlist.txt"`
done
anbu23
February 14, 2007, 4:20am
2
Remove the double quotes
UTEMP=`fgrep $USERID $REPORT_ROOT/userlist.txt`
If I remove the double quotes I lose the variable.. then the error becomes "fgrep: :: No such file or directory"
anbu23
February 14, 2007, 4:37am
4
can you show trace of your script?
Do you meen this with trace?
[nasadmin@ns600cs_kk4 quotas_michel]$ ./quota.sh
fgrep: for: No such file or directory
fgrep: user: No such file or directory
fgrep: quotas: No such file or directory
fgrep: on: No such file or directory
fgrep: filesystem: No such file or directory
fgrep: user1: No such file or directory
fgrep: mounted: No such file or directory
fgrep: on: No such file or directory
fgrep: /root_vdm_1/user1:: No such file or directory
Report for user quotas on filesystem user1 mounted on /root_vdm_1/user1
+------------+---------------------------------+-------------------------------+
fgrep: :: No such file or directory
User
+------------+--------+-------+-------+--------+--------+------+------+--------+
fgrep: :: No such file or directory
+------------+--------+-------+-------+--------+--------+------+------+--------+
fgrep: :: No such file or directory
5003
fgrep: :: No such file or directory
5005
fgrep: :: No such file or directory
5006
fgrep: :: No such file or directory
5007
anbu23
February 14, 2007, 5:01am
6
Add this code at the start of your script and show the trace
set -vx
#-------------------------------------------------------------------------------------------
NAS_DB=/nas
++ NAS_DB=/nas
NAS_BIN=${NAS_DB}/bin
++ NAS_BIN=/nas/bin
NAS_SBIN=${NAS_DB}/sbin
++ NAS_SBIN=/nas/sbin
PATH=${PATH}:${NAS_BIN}:${NAS_SBIN}
++ PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/nasadmin/bin:/nas/bin:/nas/bin:/nas/sbin
export NAS_DB PATH
++ export NAS_DB PATH
REPORT_ROOT=/home/nasadmin/quotas_michel
++ REPORT_ROOT=/home/nasadmin/quotas_michel
# datum ophalen
#-------------------------------------------------------------------------------------------
REPORT_DATE=`date +%D,%T`
date +%D,%T
+++ date +%D,%T
++ REPORT_DATE=02/14/07,11:30:28
# Lijst met gebruikers ophalen
#-------------------------------------------------------------------------------------------
cat /nas/cifs/usrmapperV3/autoumupload/server_2_newpasswd | cut -d\: -f1,3,5 > userlist.txt
++ cat /nas/cifs/usrmapperV3/autoumupload/server_2_newpasswd
++ cut -d: -f1,3,5
# Lijsten genereren van filesystemen waar quota's op staan
#-------------------------------------------------------------------------------------------
#for i in 1
#do
nas_quotas -user -report -fs user1 > user1.txt
++ nas_quotas -user -report -fs user1
cat user1.txt | while read LINE
do
USERID=`echo $LINE | cut -f 2 -d\| | cut -d# -f2`
USED=`echo $LINE | cut -f3 -d\|`
SOFT=`echo $LINE | cut -f4 -d\|`
HARD=`echo $LINE | cut -f5 -d\|`
UTEMP=`fgrep \:$USERID\: /home/nasadmin/quotas_michel/userlist.txt`
#USERNAME=`echo $UTEMP | cut -d: -f1`
echo $USERID
done
++ cat user1.txt
++ read LINE
echo $LINE | cut -f 2 -d\| | cut -d# -f2
+++ echo Report for user quotas on filesystem user1 mounted on /root_vdm_1/user1
+++ cut -f 2 '-d|'
+++ cut -d# -f2
++ USERID=Report for user quotas on filesystem user1 mounted on /root_vdm_1/user1
echo $LINE | cut -f3 -d\|
+++ echo Report for user quotas on filesystem user1 mounted on /root_vdm_1/user1
+++ cut -f3 '-d|'
++ USED=Report for user quotas on filesystem user1 mounted on /root_vdm_1/user1
echo $LINE | cut -f4 -d\|
+++ echo Report for user quotas on filesystem user1 mounted on /root_vdm_1/user1
+++ cut -f4 '-d|'
++ SOFT=Report for user quotas on filesystem user1 mounted on /root_vdm_1/user1
echo $LINE | cut -f5 -d\|
+++ echo Report for user quotas on filesystem user1 mounted on /root_vdm_1/user1
+++ cut -f5 '-d|'
++ HARD=Report for user quotas on filesystem user1 mounted on /root_vdm_1/user1
fgrep \:$USERID\: /home/nasadmin/quotas_michel/userlist.txt
+++ fgrep :Report for user quotas on filesystem user1 mounted on /root_vdm_1/user1: /home/nasadmin/quotas_michel/userlist.txt
fgrep: for: No such file or directory
fgrep: user: No such file or directory
fgrep: quotas: No such file or directory
fgrep: on: No such file or directory
fgrep: filesystem: No such file or directory
fgrep: user1: No such file or directory
fgrep: mounted: No such file or directory
fgrep: on: No such file or directory
fgrep: /root_vdm_1/user1:: No such file or directory
++ UTEMP=
++ echo Report for user quotas on filesystem user1 mounted on /root_vdm_1/user1
Report for user quotas on filesystem user1 mounted on /root_vdm_1/user1
++ read LINE
echo $LINE | cut -f 2 -d\| | cut -d# -f2
+++ echo +------------+---------------------------------+-------------------------------+
+++ cut -f 2 '-d|'
+++ cut -d# -f2
++ USERID=+------------+---------------------------------+-------------------------------+
echo $LINE | cut -f3 -d\|
+++ echo +------------+---------------------------------+-------------------------------+
+++ cut -f3 '-d|'
++ USED=+------------+---------------------------------+-------------------------------+
echo $LINE | cut -f4 -d\|
+++ echo +------------+---------------------------------+-------------------------------+
+++ cut -f4 '-d|'
++ SOFT=+------------+---------------------------------+-------------------------------+
echo $LINE | cut -f5 -d\|
+++ echo +------------+---------------------------------+-------------------------------+
+++ cut -f5 '-d|'
++ HARD=+------------+---------------------------------+-------------------------------+
fgrep \:$USERID\: /home/nasadmin/quotas_michel/userlist.txt
+++ fgrep :+------------+---------------------------------+-------------------------------+: /home/nasadmin/quotas_michel/userlist.txt
++ UTEMP=
++ echo +------------+---------------------------------+-------------------------------+
+------------+---------------------------------+-------------------------------+
++ read LINE
echo $LINE | cut -f 2 -d\| | cut -d# -f2
+++ echo '|User' '|' Bytes Used '(1K)' '|' Files '|'
+++ cut -f 2 '-d|'
+++ cut -d# -f2
++ USERID=User
echo $LINE | cut -f3 -d\|
+++ echo '|User' '|' Bytes Used '(1K)' '|' Files '|'
+++ cut -f3 '-d|'
++ USED= Bytes Used (1K)
echo $LINE | cut -f4 -d\|
+++ echo '|User' '|' Bytes Used '(1K)' '|' Files '|'
+++ cut -f4 '-d|'
++ SOFT= Files
echo $LINE | cut -f5 -d\|
+++ echo '|User' '|' Bytes Used '(1K)' '|' Files '|'
+++ cut -f5 '-d|'
++ HARD=
fgrep \:$USERID\: /home/nasadmin/quotas_michel/userlist.txt
+++ fgrep :User : /home/nasadmin/quotas_michel/userlist.txt
fgrep: :: No such file or directory
++ UTEMP=
++ echo User
User
++ read LINE
echo $LINE | cut -f 2 -d\| | cut -d# -f2
+++ echo +------------+--------+-------+-------+--------+--------+------+------+--------+
+++ cut -f 2 '-d|'
+++ cut -d# -f2
++ USERID=+------------+--------+-------+-------+--------+--------+------+------+--------+
echo $LINE | cut -f3 -d\|
+++ echo +------------+--------+-------+-------+--------+--------+------+------+--------+
+++ cut -f3 '-d|'
++ USED=+------------+--------+-------+-------+--------+--------+------+------+--------+
echo $LINE | cut -f4 -d\|
+++ echo +------------+--------+-------+-------+--------+--------+------+------+--------+
+++ cut -f4 '-d|'
++ SOFT=+------------+--------+-------+-------+--------+--------+------+------+--------+
echo $LINE | cut -f5 -d\|
+++ echo +------------+--------+-------+-------+--------+--------+------+------+--------+
+++ cut -f5 '-d|'
++ HARD=+------------+--------+-------+-------+--------+--------+------+------+--------+
fgrep \:$USERID\: /home/nasadmin/quotas_michel/userlist.txt
+++ fgrep :+------------+--------+-------+-------+--------+--------+------+------+--------+: /home/nasadmin/quotas_michel/userlist.txt
++ UTEMP=
++ echo +------------+--------+-------+-------+--------+--------+------+------+--------+
+------------+--------+-------+-------+--------+--------+------+------+--------+
++ read LINE
echo $LINE | cut -f 2 -d\| | cut -d# -f2
+++ echo '|' '|' Used '|' Soft '|' Hard '|Timeleft|' Used '|' Soft '|' Hard '|Timeleft|'
+++ cut -f 2 '-d|'
+++ cut -d# -f2
++ USERID=
echo $LINE | cut -f3 -d\|
+++ echo '|' '|' Used '|' Soft '|' Hard '|Timeleft|' Used '|' Soft '|' Hard '|Timeleft|'
+++ cut -f3 '-d|'
++ USED= Used
echo $LINE | cut -f4 -d\|
+++ echo '|' '|' Used '|' Soft '|' Hard '|Timeleft|' Used '|' Soft '|' Hard '|Timeleft|'
+++ cut -f4 '-d|'
++ SOFT= Soft
echo $LINE | cut -f5 -d\|
+++ echo '|' '|' Used '|' Soft '|' Hard '|Timeleft|' Used '|' Soft '|' Hard '|Timeleft|'
+++ cut -f5 '-d|'
++ HARD= Hard
fgrep \:$USERID\: /home/nasadmin/quotas_michel/userlist.txt
+++ fgrep : : /home/nasadmin/quotas_michel/userlist.txt
fgrep: :: No such file or directory
[nasadmin@ns600cs_kk4 quotas_michel]$ less errorlog.txt
anbu23
February 14, 2007, 5:39am
8
You are creating the file in the directory where you kept your script.Did you keep your script in "/home/nasadmin/quotas_michel" ?
cat /nas/cifs/usrmapperV3/autoumupload/server_2_newpasswd | cut -d\: -f1,3,5 > userlist.txt
The line which you read from user1.txt is not separated by pipe.Remove unnecessary lines from user1.txt
echo $LINE | cut -f 2 -d\| | cut -d# -f2
+++ echo Report for user quotas on filesystem user1 mounted on /root_vdm_1/user1
+++ cut -f 2 '-d|'
+++ cut -d# -f2
++ USERID=Report for user quotas on filesystem user1 mounted on /root_vdm_1/user1
Use double quotes
fgrep "$USERID" /home/nasadmin/quotas_michel/userlist.txt
Now I get the following output
fgrep \:"$USERID"\: /home/nasadmin/quotas_michel/userlist.txt
+++ fgrep ':5005 :' /home/nasadmin/quotas_michel/userlist.txt
++ UTEMP=
++ ECHO
For some reason the script places the ' ' before and behind the userid
anbu23
February 14, 2007, 6:24am
10
You dont need to worry about that quotes.
Do you have string ":5005 :" in the userlist.txt file?
This one exists in userlist.txt file!!
anbu23
February 14, 2007, 6:32am
12
try this
fgrep ":$USERID:" /home/nasadmin/quotas_michel/userlist.txt
This gives the same result!! When I look at the fgrep command it looks like the script puts a space behind is.
this is what is searches for fgrep '5005 ' userlist.txt
anbu23
February 14, 2007, 7:12am
14
The script does not include space. The space is there in the variable USERID.Try this
fgrep ":${USERID%% *}:" /home/nasadmin/quotas_michel/userlist.txt
It works!! Can u explain to me what u have done so can actually understand it?
anbu23
February 14, 2007, 7:36am
16
${string%%substring}
Strips longest match of $substring from back of $string.
${USERID%% *} Removes all the blanks from the end of the string
For example let USERID="5000 10 "
fgrep $USERID file
This code will expand to
fgrep 5000 10 file
Here 5000 is the search pattern and 10 and file will be taken as two files. To avoid this problem we can use quotes around the the variable.
fgrep "${USERID%% *}" file
Thanks for your help. I understand now!!