Link to home
Start Free TrialLog in
Avatar of ittechlab
ittechlabFlag for Canada

asked on

script question

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
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

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
Avatar of pepr
pepr

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

ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial