Run Post Script on ubuntu



  • 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:

    [code]
    #!/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
    [/code]

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



  • 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.



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



  • 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



  • OK then my previous comment is correct. You are modifying the wrong filesystem. You just need to mount the partition.
    Something like.
    [code]mkdir /mnt/fs
    mount /dev/sda2 /mnt/fs[/code]
    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



  • Also for your task of renaming the interface, I have had success in simply removing the persistent-net.rules
    [code]rm -f /etc/udev/rules.d/70-persistent-net.rules[/code]



  • Here is my post script after some changes:

    [code]

    #!/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

    [/code]

    tested on ubuntu 12