bash - Using the first column of a file as input in a script -


i having problems using first column ${1} input script.

currently portions of script looks this.

#!/bin/bash  input="${1}" name in `cat ${input}`     size="`du -sm /faserver/na3250-a/homes/${name} | sed 's|/faserver/na3250-a/homes/||'`"     datestamp=`ls -ld /faserver/na3250-a/homes/${name} | awk '{print $6}'` echo "${size} ${datestamp}" done 

however, want modify input="${1}" take first {1} within specific file. can run lines above in script , use file generated input. have output go out new file.

so like:

input="$location/disabledactivehome ${1}"   ??? 

here's full script below.

#!/bin/bash # script search through disabled users ou , compare list of # names against current active home directories. find out # how space home directories take , need removed.  # must run sudo!  # setting variables _adm , storage path.  echo "please provide _adm account name:" read _adm echo "please state want files generated: (absolute path)" read location  # string of commands lookup information using ldapsearch  ldapsearch -x -lll -h "redacted" -d $_adm@"redacted" -w -b "ou=accounts,ou=disabled_objects,dc="xx",dc="xx",dc="xx"" "cn=*" | grep 'samaccountname'| egrep -v '_adm$' | cut -d' ' -f2 > $location/disabledhome  # list of active home directories  ls /faserver/na3250-a/homes > $location/activehome  # compare disabled accounts against active home directories  grep -o -f $location/disabledhome $location/activehome > $location/disabledactivehome  # size , datestamp disabled folders  input="${1}" name in `cat ${input}`     size="`du -sm /faserver/na3250-a/homes/${name} | sed 's|/faserver/na3250-a/homes/||'`"     datestamp=`ls -ld /faserver/na3250-a/homes/${name} | awk '{print $6}'` echo "${size} ${datestamp}" done 

i'm new of welcome. happy clarify , questions might have.

edit: little more explanation because i'm terrible @ these things.

the lines of code below came previous script loop:

input="${1}"     name in `cat ${input}`             size="`du -sm /faserver/na3250-a/homes/${name} | sed 's|/faserver/na3250-a/homes/||'`"         datestamp=`ls -ld /faserver/na3250-a/homes/${name} | awk '{print $6}'`     echo "${size} ${datestamp}"     done 

it executed typing:

./script ./file  

the file being referenced has 1 column of user names , no other data:

user1 user2 user3 etc. 

the script take file , @ first users name, reference by

input=${1} 

then run du command on user , find out size of home drive is. reported size variable. same thing datestamp in regards when home drive created user. when done doing tasks user, move on next 1 in column until done.

so following logic, want automate entire process. instead of doing in 2 steps, make 1 step process.

the first process generate $location/disabledactivehome file, have of disabled users names. run last portion size , creation date of each home drive users in disabledactivehome file.

so that, need modify the

input=${1} 

line reflect generated file.

$location/disabledactivehome 

i don't understand question really, think want this. file called file.txt , looks this:

1 99 2 98 3 97 4 96 

you can first column this:

awk '{print $1}' file.txt 1 2 3 4 

if want use in script, this

while read name;      echo $name done < <(awk '{print $1}' file.txt) 1 2 3 4 

or may prefer cut this:

while read name;     echo $name done < <(cut -d" " -f1 file.txt) 1 2 3 4 

or may suit better

while read name otherunwantedjunk;    echo $name done < file.txt 1 2 3 4 

this last, , best, solution above uses ifs, bash's input field separator, if file looked this

1:99 2:98 3:97 4:96 

you this

while ifs=":" read name otherunwantedjunk;    echo $name done < file.txt 1 2 3 4 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -