LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-16-2010, 09:51 AM   #1
msarro
LQ Newbie
 
Registered: Sep 2010
Posts: 3

Rep: Reputation: 0
Using Echo to create a complex script


Hey everyone. This is kind of a weird question, but I need ya'll to trust me.

We're going to be doing a rather large server deployment, and using the provisioning system we have in place there is no current way to just "copy" a file over to the servers. All files/scripts have to be run from the provisioning server.

Due to network constraints, the provisioning system can't run a script we need to run (requires certain network assets to complete, but as soon as we modify the network settings the provisioning system loses access to the server and can't run the script). So, I need our network configuration script to create the other script on the server in /root when it runs.

My original method was to do something along the lines of:

Code:
#network configuration statements here
....
#Create satellite registration script
echo <statements> > /root/satReg.sh
echo <morestatements> >> /root/satReg.sh
...
#restarting network services cuts connectivity with provisioning server by making new network configuration take affect
/etc/init.d/network restart
exit 0
This would be fine except for the fact that echo runs into issues with if statements and other special characters (;, (), [], etc), and starts spitting out errors. I tried using escape (\) characters with a number of the symbols but it doesn't look like its working. Is there any way to use echo to just spit out a bunch of text without trying to parse it for special characters?

Is there another way to use one script to spit out another, more complex script?

Any advice would really be appreciated.
 
Old 09-16-2010, 10:01 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
I believe a here document is what you might be after:
Code:
#!/bin/bash

cat > mynewfile <<"EOF"
#!/bin/bash

[[ -f mynewfile ]] && echo "yes it exists"

EOF

chmod 777 mynewfile

#rest of script
The word can be anything you like, but EOF is quite often used for obvious reasons.

Also, in quotes there is no parameter expansion but if you need variables to be expanded then leave the quotes out.
 
1 members found this post helpful.
Old 09-16-2010, 10:15 AM   #3
msarro
LQ Newbie
 
Registered: Sep 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by grail View Post
I believe a here document is what you might be after:
Code:
#!/bin/bash

cat > mynewfile <<"EOF"
#!/bin/bash

[[ -f mynewfile ]] && echo "yes it exists"

EOF

chmod 777 mynewfile

#rest of script
The word can be anything you like, but EOF is quite often used for obvious reasons.

Also, in quotes there is no parameter expansion but if you need variables to be expanded then leave the quotes out.
That worked like a charm, thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can we create a text Based Menu for complex Linux Operations k41184 Linux - Software 15 04-27-2014 12:49 AM
[SOLVED] Delete files with complex filenames with a script NickJH Linux - Newbie 24 05-26-2010 08:55 AM
help with complex bash script-XML handling panoskan Programming 4 09-18-2008 07:19 PM
LXer: aiSee helps create graphs with complex layouts LXer Syndicated Linux News 0 06-02-2008 03:41 PM
How to enable complex script support in Firefox on Suse 9.3/10 Chaitany Linux - Software 2 11-18-2006 01:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration