?
Solved

script question

Posted on 2013-02-06
3
Medium Priority
?
207 Views
Last Modified: 2013-02-23
I wanted to write the following lines to file called "myprofile" as following. How can i write it?

I wrote a function called create_profile.

create_profile(){
echo install_type initial_install
system_type standalone
partitioning explicit
filesys c0t0d0s0 4096 /
filesys c0t0d0s1 2048 swap
filesys c0t0d0s3 2048 /var
filesys c0t0d0s4 2048 /usr
filesys c0t0d0s5 2048 /opt >> myprofile
0
Comment
Question by:ittechlab
[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
3 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 38861570
question is not clear, please elaborate

is this what you want:

create_profile(){
echo "install_type initial_install
system_type standalone
partitioning explicit
filesys c0t0d0s0 4096 /
filesys c0t0d0s1 2048 swap
filesys c0t0d0s3 2048 /var
filesys c0t0d0s4 2048 /usr
filesys c0t0d0s5 2048 /opt" >> myprofile
0
 
LVL 29

Expert Comment

by:pepr
ID: 38861701
The straightforward rewrite is as follows:
def create_profile(fname):
    with open(fname, 'a') as f:
        f.write("""install_type initial_install
system_type standalone
partitioning explicit
filesys c0t0d0s0 4096 /
filesys c0t0d0s1 2048 swap
filesys c0t0d0s3 2048 /var
filesys c0t0d0s4 2048 /usr
filesys c0t0d0s5 2048 /opt""")

# Later, you can call the function.
create_profile('myprofile')

Open in new window

You can hardwire the filename inside
def create_profile():
    with open('myprofile', 'a') as f:
        f.write("""install_type initial_install
system_type standalone
partitioning explicit
filesys c0t0d0s0 4096 /
filesys c0t0d0s1 2048 swap
filesys c0t0d0s3 2048 /var
filesys c0t0d0s4 2048 /usr
filesys c0t0d0s5 2048 /opt""")


create_profile()

Open in new window

0
 
LVL 48

Accepted Solution

by:
Tintin earned 1095 total points
ID: 38862831
What programming language do you want it in?  If shell, then do

create_profile() {
cat >>myprofile <<EOF
install_type initial_install
system_type standalone
partitioning explicit
filesys c0t0d0s0 4096 /
filesys c0t0d0s1 2048 swap
filesys c0t0d0s3 2048 /var
filesys c0t0d0s4 2048 /usr
filesys c0t0d0s5 2048 /opt 
EOF
}

Open in new window

0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses

771 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