shell script to take input from user , a list of directory path into file and enter each directory make changes to file
Requirement---URGENT for production server----------please check for my syntaxes if possible-------------
echo path cat >> path.txt /app/tomcat7/webapps/sessionchecking.class ----- directory paths may increase in size or number ------ /app1/tomcat1/webapps1/Home.jsp /app2/tomcat2/webapps2/struts.xml ctrl-d cat path.txt | while read line do pathvariable="$line" base=$(basename ($pathvariable)) dir=$(dirname ($pathvariable)) echo $base echo $dir cd "$dir" -------------need to clear the contents of dir after processing ----------- mv $base /Contexts/backup scp 10.3.x.x:/root/Downloads/sessionchecking.class . done |
Welcome to LQ!
While your requirements may be urgent to yourself, please understand that members here volunteer their time and may choose which questions they wish to reply to, and when. If this is related to your work as it appears to be, you would be better advised to seek help from a coworker who would be familiar with the application environment and any operational constraints. If the script is not working as expected, please describe how it is invoked and how operation differs from what you expect. Be sure to include any error messages received. Please review the Site FAQ for guidance in posting your questions and general forum usage. Especially, read the link in that page, How To Ask Questions The Smart Way. The more effort you put into understanding your problem and framing your questions, the better others can help! |
Quote:
Please edit your first post, replace this line with a humble request without the word "urgent", and put your code in CODE tags. You also need to tell it (and us) which shell you're using, e.g. Code:
#!/bin/tcsh |
Quote:
Quote:
Quote:
|
One mistake fixed:
Code:
base=$(basename "$pathvariable") |
Besides the guidance already given, suggest you use Shell Check which is a site where you can post your script and it will provide feedback for exactly what you're asking, a syntax check.
But bear in mind that you can check your own syntax, by running your script and also doing things like enabling verbose output and debug with lines like "set -xv" |
Quote:
I apologize , i was unaware of the question guidelines And to be frank i am a server admin , and a complete newbie to world of scripting But In due course of my work I found out shell scripting to be very useful in automating server work and i am in my learning process Hence this script is something I have prepared reading some programs and scripts and tutorials online I would like to thank for pointing out the syntax and please guide me for the above script as i have been struggling from long time query : the path app/tomcat7/webapps is taken as a string in to the variable but when we are entering with the help of script into directory ex : < cd /app/tomcat7/webapps > its echoing pwd as /app/tomcat7/webapps which is correct But with a while loop its not entering into the second path < cd /app1/tomcat1/webapps1 > and not echoing the $PWD variable |
Quote:
Quote:
Example: https://www.cyberciti.biz/faq/unix-h...ine-from-file/ |
I could be wrong but if the depth where the files you need may change and if the files you are requesting have always the same name then why not :
- use find command to search for the file in app directory - retrieve the full path of the file from find output - and then move the file to where you want or do whatever you need ahead after having the correct locations of the files . |
Quote:
|
Quote:
Again, you were given links to tutorials showing you how to do what you want. |
Quote:
:D Two sites were already recommended, here's a third: http://mywiki.wooledge.org/BashGuide Contains answers to your question. Ans you still didn't remove the insult from your first post. Nor did you put your code in CODE tags. |
Quote:
|
Quote:
That said...things are different now. While I totally get that a contract company doesn't want their folks shoveling out software off the books, doing a basic bash script for automating a process is different. |
All times are GMT -5. The time now is 03:51 AM. |