Solved

Help Needed with Bash Script

Posted on 2014-01-07
1
341 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Fine Tune your automatic Updates for Ubuntu / Debian
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

717 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