Solved

Help Needed with Bash Script

Posted on 2014-01-07
1
339 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sqlldr issue 1 16
LogmeIn using Linux Ubuntu 16.04 6 65
what do I need to host my own web sites? 13 52
AWK: Pythagoras script 6 23
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

830 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