Run Post Script on ubuntu

  1. last year
    Edited last year by dor

    Hi,

    I have tried to push on Demand Image.

    The Image was deploy as expected but the post script wasn't worked.

    Server OS in the image: Ubuntu 12.04.5 LTS

    Part of the log that related to the script:
    image_name=hpdl380g8 profile_id=5 server_ip=10.100.110.94 multicast=false pre_scripts="" post_scripts="1 " file_copy=False sysprep_tags="" task_completed_action="Reboot" dp_id=1 image_direction=push osx_target_volume="" munki_repo_url="" change_computer_name=true fix_bootloader=true partition_method=dynamic custom_deploy_schema=true custom_hard_drives="/dev/sda " task=push computer_name=test
    .....
    ** Running Custom Script With Id 1 **
    ....

    The script:

    #!/bin/bash
    serverip=########
    dev1=$(ip -o link show | awk '{print $2}' | tr -d ":" | grep eth | sort | head -n1)
    
    
    cat << EOF >/etc/network/interfaces
    auto lo
    iface lo inet loopback
    
    auto ${dev1}
    iface ${dev1} inet static
            address ${serverip}
            netmask ########
            gateway ########
            dns-nameservers ######## ########
            dns-search ########
    
    EOF

    The post script is not working. Am I doing something wrong? syntax?

    Also for your task of renaming the interface, I have had success in simply removing the persistent-net.rules

    rm -f /etc/udev/rules.d/70-persistent-net.rules
  2. clonedeploy

    23 Mar 2017 Administrator

    It looks like your script is running against the currently loaded filesystem. You need to mount the correct partition and change your paths to reflect that.

  3. clonedeploy

    23 Mar 2017 Administrator

    Or maybe I'm misunderstanding what you are trying to do?

  4. After deploy the image the network device name changed. For example from eth0 to eth2 (probably because the uuid of the nic is different from the image). So i'm trying to replace the device name of the network conf to the right device name. And change the ip

  5. clonedeploy

    23 Mar 2017 Administrator

    OK then my previous comment is correct. You are modifying the wrong filesystem. You just need to mount the partition.
    Something like.
    mkdir /mnt/fs mount /dev/sda2 /mnt/fs
    Then change
    etc/network/interfaces
    to
    /mnt/fs/etc/network/interfaces

    You can also append any info you would like to the client log, ex:
    echo "Test" >> $CLIENT_LOG

  6. clonedeploy

    23 Mar 2017 Administrator Answer

    Also for your task of renaming the interface, I have had success in simply removing the persistent-net.rules

    rm -f /etc/udev/rules.d/70-persistent-net.rules
  7. Edited last year by dor

    Here is my post script after some changes:

    #!/bin/bash
    serverip='###########'
    servernetmask='###########'
    servergateway='###########'
    serverdnsone='###########'
    serverdnssec='###########'
    serverdnssuffix='###########'
    
    mkdir /mnt/fs 
    mount /dev/sda2 /mnt/fs
    rm -f /mnt/fs/etc/udev/rules.d/70-persistent-net.rules
    
    
    cat << EOF >/mnt/fs/etc/network/interfaces
    auto lo
    iface lo inet loopback
    
    auto eth0
    iface eth0 inet static
            address ${serverip}
            netmask ${servernetmask}
            gateway ${servergateway}
            dns-nameservers ${serverdnsone} ${serverdnssec}
            dns-search ${serverdnssuffix}
    
    EOF
    

    tested on ubuntu 12

 

or Sign Up to reply!