?
Solved

Help Needed with Bash Script

Posted on 2014-01-07
1
Medium Priority
?
343 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 2000 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

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 …
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month9 days, left to enroll

764 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