Solved

script question

Posted on 2013-02-06
3
200 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
3 Comments
 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
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 28

Expert Comment

by:pepr
Comment Utility
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 365 total points
Comment Utility
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now