Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

script question

Posted on 2013-02-06
3
Medium Priority
?
210 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Fine Tune your automatic Updates for Ubuntu / Debian
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

618 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