Solved

Help Needed with Bash Script

Posted on 2014-01-07
1
337 Views
Last Modified: 2014-01-07
Can anyone explain the below bash script line-by-line.

#!/usr/bin/bash 

find -type d > dir.lst
  while
	read i
  do
     cd $1/$i
     mv * $1/../done/$i/.
     cd $1/../stud
     find . -name "*.xml" -exec ./stud_filter.sh {} \;
     echo \$ fwdXML "*.xml"|/usr/bin/ftp sid.student.com
     mkdir $1/../done/stud/$i 2>/dev/null
     mv * $1/../done/stud/$i/.
  done < dir.lst
  rm dir.lst

Open in new window

0
Comment
Question by:gaugeta
1 Comment
 
LVL 31

Accepted Solution

by:
farzanj earned 500 total points
ID: 39762490
#!/usr/bin/bash  #Must be first line-->Called shebang. Location of Bash interpreter 

#Finding all the directories -- type d means directories, stored to file dir.lst
find -type d > dir.lst

#Reading file dir.lst line by line, each line then stored in variable i
  while	read i
  do

    #change directory, $1 is command line parameter, $i is read from file
     cd $1/$i

     #move file from given location to the done folder.  Two dots mean parent directory
     mv * $1/../done/$i/.

     #Change directory again  .. parent directory of $1 to child stud
     cd $1/../stud

     #finding files with xml extension and passing them to the script stdu_filter.sh
     find . -name "*.xml" -exec ./stud_filter.sh {} \;

     #pass/pipe $fwdXML "xml filename" to ftp
     echo \$ fwdXML "*.xml"|/usr/bin/ftp sid.student.com

     #Make directory, dump error messages
     mkdir $1/../done/stud/$i 2>/dev/null

     #Another move as explained
     mv * $1/../done/stud/$i/.
  done < dir.lst

  #cleanup step, remove this tmp file
  rm dir.lst

Open in new window

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now