shell script to take input from user , a list of directory path into file and enter each directory make changes to file
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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"
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
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!
Requirement---URGENT for production server----------please check for my syntaxes if possible-------------
How extremely impolite!
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.
Incorrect; this is NOT URGENT for anyone here, and it isn't for any of our production servers.
Quote:
----------please check for my syntaxes if possible-------------
Check syntax for what?? You haven't actually said what (if anything) is wrong. And if you were hired to do work on a server, then shouldn't you be able to debug/correct a simple shell script on your own?
Quote:
Code:
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
Since this is 'urgent', have you tried just running this script to see if it works?
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"
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!
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
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
How did you get a job as a server admin if you can't write a script??
Quote:
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
Putting "bash script read a file" into Google pulls up a LOT...the link to a bash scripting tutorial is in my posting signature, and all of this is covered. You don't say what tutorials you're following, but it's hard to know why you'd be struggling for a long time with a very basic operation.
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 .
How did you get a job as a server admin if you can't write a script??
Putting "bash script read a file" into Google pulls up a LOT...the link to a bash scripting tutorial is in my posting signature, and all of this is covered. You don't say what tutorials you're following, but it's hard to know why you'd be struggling for a long time with a very basic operation.
That's because I am in to server administration configuration and troubleshooting in my job role , u don't need to know programming to get a job in server administration in India , there are bunch of python and ansible guys to do that , only a need to know basis on scripts is required but scripts are what saving me a lot on my work ,hence I am into this now,
That's because I am in to server administration configuration and troubleshooting in my job role , u don't need to know programming to get a job in server administration in India , there are bunch of python and ansible guys to do that , only a need to know basis on scripts is required but scripts are what saving me a lot on my work ,hence I am into this now,
Read the LQ Rules about not using text-speak. This isn't a top-secret thing that's 'need-to-know', and since you want to do it, you then need to know, right???
Again, you were given links to tutorials showing you how to do what you want.
I think you need to know more about shell scripting in general.
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.
Distribution: openSUSE, Raspbian, Slackware. Older: Coherent, MacOS, Red Hat, Big Iron IXs: AIX, Solaris, Tru64
Posts: 2,267
Rep:
Quote:
Originally Posted by TB0ne
How did you get a job as a server admin if you can't write a script??
Hey... back in my VMS days, you'd be surprised how many headhunters would actually ask system manager candidates the silly question: "Do you know DCL?" IBM was not requiring UNIX admins to know anything about scripting (or any other kind of programming, for that matter) because they just about prohibit them from writing any kind of code---the contract with their clients may not include writing software -- of any kind -- as a billable service.
Hey... back in my VMS days, you'd be surprised how many headhunters would actually ask system manager candidates the silly question: "Do you know DCL?" IBM was not requiring UNIX admins to know anything about scripting (or any other kind of programming, for that matter) because they just about prohibit them from writing any kind of code---the contract with their clients may not include writing software -- of any kind -- as a billable service.
I remember DCL (and TCL) fondly...I managed a herd of Vaxen at one time. Still one of the best platforms I've ever worked on.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.