?
Solved

script question

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

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

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

Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

840 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