Results 1 to 10 of 10

Thread: How to make a script for automated editing

  1. #1
    Join Date
    Apr 2010
    Location
    i am location
    Posts
    1,421

    Default How to make a script for automated editing

    Hi, I wonder how i can make a script to automatically generate a batchfile and add commands into it.
    The whole purpose of it is, to have a script i can run at an installation and let these task be done automatically.

    I do need to learn scripting i think, but if there is a good guide someone can recommend me i am delighted to read it.

    Well, i hope i explained it right so you, the reader, knows what i want to accomplish.

    So far, i did an automated script for installing libs and adding repos. Works well so far.

    Code:
    #!/bin/bash
    
    # adding repos for non free codecs
    
    zypper addrepo -f http://packman.inode.at/suse/11.4/packman
    zypper addrepo -f http://www.opensuse-guide.org/repo/11.4 libdvdcss
    
    # adding libraries for non free codecs
    
    zypper in libavcodec52 libavdevice52 ffmpeg libmpeg libdvdnav4 libdvdread4 libquicktime0 libxine1 libxine1-codecs libxvidcore4 smplayer vlc w32codec-all xine-vi xvidcore lame
    
    # adding repos for non free Nvidia graphics driver
    
    zypper addrepo -f http://download.nvidia.com/opensuse/11.4 NVIDIA Repository
    zypper addrepo -f http://download.opensuse.org/update/11.4 Main Update
    
    # adding driver for non free Nvidia graphics card
    
    zypper install x11-video-nvidiaG02
    
    # adding repo for non free Skype
    
    zypper addrepo -f http://download.opensuse.org/repositories/home:/broumbroum23/openSUSE_11.3_NonFree_standard/ Skype
    
    # adding libs for Skype
    
    zypper install libpng12.so.0 libqt4-32bit libqt4-dbus-1-32bit libqt4-x11-32bit libsigc++2-32bit xorg-x11-libXv-32bit
    So now, all i need is a command to add lines in a scriptfile and of course generate it. The generating part is easy, but can i add a line just by using vi without calling vi.

    Thanks

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,777

    Default Re: How to make a script for automated editing

    To add lines to a file you use the >> file redirection indicator. Like
    Code:
    echo "This lines is added at the end of the file" >>script
    For more difficult actions read
    Code:
    man ed
    Also the line edidotor guises of vi could be interesting: ex/edit. Again see their man pages.
    Henk van Velden

  3. #3
    Join Date
    Apr 2010
    Location
    i am location
    Posts
    1,421

    Default Re: How to make a script for automated editing

    Quote Originally Posted by hcvv View Post
    To add lines to a file you use the >> file redirection indicator. Like
    Code:
    echo "This lines is added at the end of the file" >>script
    For more difficult actions read
    Code:
    man ed
    Also the line edidotor guises of vi could be interesting: ex/edit. Again see their man pages.
    Thanks. I think thats what i am looking for.

    I will post my script once its done. Maybe its someone else can use it too.

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,777

    Default Re: How to make a script for automated editing

    To make it more difficult for you what to choose

    There is also sed. But be carefull, as it's name states it is a "stream editor" and you must therefore not write the output of it directly to the input file, because you will overwrite your own input file before it is read completley. Thus something like:
    Code:
    sed -e ' .. ' -e ' .. ' input >output
    mv output input
    (where ' .. ' ) are of course the several edit statements) will first write output and then overwrite input.

    The others work with a buffer and will overwrite the input only after a w command (same as vi).
    Henk van Velden

  5. #5
    Join Date
    Apr 2010
    Location
    i am location
    Posts
    1,421

    Default Re: How to make a script for automated editing

    Quote Originally Posted by JoergJaeger View Post
    Thanks. I think thats what i am looking for.

    I will post my script once its done. Maybe its someone else can use it too.
    This works already perfect. The only thing it can't do is to add #!/bin/bash. Have to look that up..
    Thanks for that tip since it solved my problem.

  6. #6
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,777

    Default Re: How to make a script for automated editing

    Quote Originally Posted by JoergJaeger View Post
    This works already perfect. The only thing it can't do is to add #!/bin/bash. Have to look that up..
    Thanks for that tip since it solved my problem.
    Without further explanation I cannot be of much help. When you add statements to an existing script the #!/bin/bash is allready there. When you generate a new script an
    Code:
    echo '#!/bin/bash' >yourscipt
    at the beginning will create yourscipt and put that first line in it. What is the problem?
    Henk van Velden

  7. #7
    Join Date
    Aug 2010
    Location
    Chicago suburbs
    Posts
    15,673
    Blog Entries
    3

    Default Re: How to make a script for automated editing

    Quote Originally Posted by JoergJaeger View Post
    This works already perfect. The only thing it can't do is to add #!/bin/bash.
    It's been a while since I have done it, but something like:
    Code:
    1i\
    #! /bin/bash
    (as part of a sed script) should do that for you.

    (added in edit - thatis a digit "1" before the letter "i" for use in sed. After posting, I noticed that it looked a bit like a lower case "L".
    openSUSE Leap 15.3; KDE Plasma 5.18.6;

  8. #8
    Join Date
    Apr 2011
    Posts
    2

    Default Re: How to make a script for automated editing

    Hi, was just overlooking your post. I was wondering do you guys have any infomation on scripts that will automatically extract a file towards my customers destination (like to their usb or floppy disk etc...etc...)?
    Plus, allowing them to download the file only once without copying it to another drive or destination? I have searched the internet day in and out but still have not came across such a script, if any exsist at all. If you have any info on this....please share! Thanks

  9. #9
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,777

    Default Re: How to make a script for automated editing

    This is a completely new question and has no relation with the above. When you want that people help you with this new question then please start a new thread in Programming/Scripting with a telling title. That will draw people to your problem. Now you are hiding your problem beneath an old allready drowned thread and almost nobody will see it.
    Henk van Velden

  10. #10
    Join Date
    Mar 2009
    Location
    Burgas,Bulgaria
    Posts
    96

    Default Re: How to make a script for automated editing

    It is for my usage ,and it is not perfect steel...



    Code:
    #!/bin/bash
    # Bash script to set up some common repositories on an OpenSUSE 11.4 system.
    printf "\e[1;34m\e ###################################################################\n"
    printf "\e[1;33m\e SCRIPT TO SET UP SOFTWARE AND REPOSITORIES FOR openSUSE 11.4\n"
    printf "\e[1;34m\e ###################################################################\n"
    #printf "\e[5;31m\e ###################################################################\n"
    #printf "\e[0;32m\e ###################################################################\n\n"
    sleep 3
    # Make sure we are root.
    if [ "$EUID" != "0" ]; then
      printf "\e[5;31m\e!!! - This script must be run as root. - !!!\n\n"
      printf "\e[0;32m\e ###########################################\n\n"
      exit 1
    fi
    
    
    SUSE_VERSION=$(awk '/^VERSION/{print $3}' /etc/SuSE-release)
    
    x=$(cat /etc/SuSE-release |grep VERSION | cut -d\. -f2)
    
    if [ $x -eq 4 ]
       then 
    
    #clear
    printf "\e[0;32m\e"
    echo "======================================================================="
    echo "=                                  #####  #     #  #####  ######      ="
    echo "=                                 #     # #     # #     # #           ="
    echo "=      ####  #####  #####  ##   # #       #     # #       #           ="
    echo "=     #    # #    # #      # #  #  #####  #     #  #####  #####       ="
    echo "=     #    # #####  #####  #  # #       # #     #       # #           ="
    echo "=     #    # #      #      #   ## #     # #     # #     # #           ="
    echo "=      ####  #      ###### #    #  #####   #####   #####  ######      ="
    echo "======================================================================="
    sleep 5
    #clear
    
    
    printf "\e[1;33m\e <<<Installatin begins...\n"
    
    printf "\e[0;32m\e"
       else printf "\e[5;31m Your version is not 11.4 Exiting!\n "
    printf "\e[0;32m\e"
            sleep 4
            clear
            exit
    fi
    
    #============================================================
    
    
    #clear
    
    
    
    printf "\e[1;34m\e ###################################################################\n"
    printf "\e[1;33m\e Setting up repositories... FOR openSUSE 11.4\n"
    printf "\e[1;34m\e ###################################################################\n"
    sleep 3
    printf "\e[0;32m\e"
    
    IFS=$','
    repo[1]="Packman,http://packman.unixheads.com/suse/11.4/"
    repo[2]="DVD Libraries,http://opensuse-guide.org/repo/11.4/"
    repo[3]="KDE Updated,http://download.opensuse.org/repositories/KDE:/UpdatedApps/openSUSE_11.4/"
    repo[4]="KDE Extra,http://download.opensuse.org/repositories/KDE:/Extra/openSUSE_11.4/"
    repo[5]="Factory Contrib,http://download.opensuse.org/repositories/openSUSE:/Factory:/Contrib/openSUSE_11.4"
    repo[6]="skype,http://download.opensuse.org/repositories/home:/broumbroum23/openSUSE_11.3_NonFree_standard/"
    repo[7]="google-talkplugin,http://dl.google.com/linux/talkplugin/rpm/stable/x86_64"
    #repo[8]="nVidia,ftp://download.nvidia.com/opensuse/11.4/"
    #repo[9]="ATI/AMD,http://www2.ati.com/suse/11.4/"
    #repo[10]="ATI/AMD fglrx non-official,http://linux.ioda.net/mirror/ati/openSUSE_11.4/"
    #repo[11]="VLC,http://download.videolan.org/pub/vlc/SuSE/11.4"
    #repo[12]="OpenSUSE 11.4-Updates,http://download.opensuse.org/update/11.4/"
    #repo[13]="OpenSUSE 11.4-OSS,http://download.opensuse.org/distribution/11.4/repo/oss/"
    #repo[14]="openSUSE 11.4 Source,http://download.opensuse.org/source/distribution/11.4/repo/oss/"
    #repo[15]="openSUSE 11.4 Non-OSS,http://download.opensuse.org/distribution/11.4/repo/non-oss/"
    #repo[16]="openSUSE 11.4 Debug,http://download.opensuse.org/debug/distribution/11.4/repo/oss/"
    #repo[17]="Tumbleweed,http://download.opensuse.org/repositories/openSUSE:/Tumbleweed/standard/"
    #repo[18]="Tumbleweed-Packman,http://packman.inode.at/suse/openSUSE_Tumbleweed/Essentials"
    
    ######################################################################
    cnt=${#repo[@]}
    for (( i = 0 ; i < cnt ; i++ ))
    	do
    	j=0
    	for PART in ${repo[$i]}
    		do
    		if [ $j == 0 ] ; then
    			name=$PART
    			j=1
    		else
    			url=$PART
    			j=0
    		fi
    	done
    	zypper ar "$url" "$name"
    	zypper mr -r "$name"
    	zypper --no-gpg-checks --gpg-auto-import-keys refresh -f "$name"
    done
    
    printf "\n\n################################################################################\n"
    printf "\e[1;33m\e SET UP SOFTWARE REPOSITORIES finished... (make sure to remove duplicates):\n"
    printf "####################################################################################\n\n"
    printf "\e[0;32m\e"
    sleep 3
    clear
    printf "\n\n################################################################################\n"
    printf "\e[1;33m\e BEGIN INSTALL SOFTWARE.... \n"
    printf "####################################################################################\n\n"
    printf "\e[0;32m\e"
    sleep 3
    clear
    
    IFS=$','
    soft[1]="acetoneiso2 "
    soft[2]="vlc"
    soft[3]="MPlayer"
    soft[4]="SMPlayer"
    soft[5]="wine"
    soft[6]="stardict"
    soft[7]="unison"
    soft[8]="vlc-mozillaplugin"
    soft[9]="yakuake"
    soft[10]="rkhunter"
    soft[11]="chkrootkit"
    soft[12]="dropbox"
    soft[13]="gtk2-devel"
    soft[14]="libcurl-devel"
    soft[15]="make"
    soft[16]="gcc"
    soft[17]="libdvdcss2"
    soft[18]="ffmpeg"
    soft[19]="flac"
    soft[20]="k3b-codecs"
    soft[21]="libxine1-codecs"
    soft[22]="phonon-backend-xine"
    soft[23]="w32codec-all"
    soft[24]="gstreamer-0_10-ffmpeg"
    soft[25]="gstreamer-0_10-fluendo-mpegdemux"
    soft[26]="gstreamer-0_10-fluendo-mpegmux"
    soft[27]="gstreamer-0_10-plugins-base"
    soft[28]="gstreamer-0_10-plugins-good-extra"
    soft[29]="gstreamer-0_10-plugins-ugly"
    soft[30]="gstreamer-0_10-plugins-bad"
    soft[31]="ImageMagick-extra"
    soft[32]="fetchmsttfonts"
    soft[33]="akonadi-googledata"
    soft[34]="libnotify-tools"
    soft[35]="autossh"
    soft[36]="lynis"
    soft[37]="fail2ban"
    soft[38]="sshguard"
    soft[39]=""
    soft[40]=""
    ##################################
    cnt=${#soft[@]}
    for (( i = 0 ; i < cnt ; i++ ))
    	do
    	j=0
    	for PART in ${soft[$i]}
    		do
    		if [ $j == 0 ] ; then
    			s=$PART
    			j=1
    		else
    			s=$PART
    			j=0
    		fi
    	done
    	zypper install -y -l "$s" 
    	
    done
    
    sleep 30
    clear
    printf "\n\n################################################################################\n"
    printf "\e[1;33m\e INSTALL CODECS is finished... \n"
    printf "####################################################################################\n\n"
    sleep 3
    clear
    
    ###################################################################
    #set cron
    cd /etc/sysconfig/
    
    cat cron |awk '/CLEAR_TMP_DIRS_AT_BOOTUP/ { gsub(/no/, "yes") };
    /MAX_DAYS_IN_TMP/ { gsub(/0/, "1") };
    /LONG_TMP_DIRS_TO_CLEAR/ { gsub(/""/, "\"/var/tmp\"") };
    /MAX_DAYS_IN_LONG_TMP/ { gsub(/0/, "28") }; { print }'>>cr
    sleep 3
    mv cr cron
    cd
    ######################################################
    #Install mozilla addons
    mkdir /home/$USER/INSTAL
    cd /home/$USER/INSTAL
    ext="ext.tar.gz"
    ad="http://dl.dropbox.com/u/8046742/$ext"
    
    wget -q $ad
    tar -xzf $axt
    mv -f extensions /home/$USER/.mozilla/firefox/PROFIL.default/extensions/ #!
    
    #############################################################
    #Install audiometadata service menu
    aud="audiokonverter-5.9.1-4.1.noarch.rpm"
    adr="http://dl.dropbox.com/u/8046742/$aud"
    
    wget -q $aud
    zypper install -y $aud
    
    ###############################################################
    #Install Dropbox service menu
    drb="DropboxServiceMenu-0.15.2.tar.gz"
    adre="http://dl.dropbox.com/u/8046742/$drb"
    
    wget -q $adre
    tar -xzf $drb
    cd ~/DropboxServiceMenu-0.15.2
    exec ./install-it.sh
    cd ..
    
    ##############################################################
    #Install Run-in-konsole service menu
    kon="konsole.desktop.tar.gz"
    adres="http://dl.dropbox.com/u/8046742/$kon"
    
    wget -q $adres
    tar -xzf $kon
    cp run-script-in-konsole.desktop /home/$USER/.kde4/share/kde4/services/
    
    
    ##############################################################
    
    # This script installs Stardict with eng-bul/bui-eng dicts?
    
    n="stardict.tar.bz"
    #b="5748864"
    uri="http://dl.dropbox.com/u/8046742/$n"
    
    if  [ -e ~/$n ];
    then
        tar -xzf $n
    
    else
        echo -en "Downloading and Installing dicts..."
        wget $uri
        tar -xzf $n # Extract the dicts
        
    fi
    
    mv stardict-bgoffice_bul-eng-2.4.2 /usr/share/stardict/dic
    mv stardict-bgoffice_eng-bul-2.4.2 /usr/share/stardict/dic
    mv stardict.tar.bz /tmp
    rm /tmp/stardict.tar.bz 
    
    
    
    ######################################################################
    # Инсталиране на ТВхелпер?
    ni="tvhelper-1.1.5.tar.gz"
    nii="tvhelper.tar.bz2"
    uri="http://openfmi.net/frs/download.php/486/$ni"
    urii="http://dl.dropbox.com/u/8046742/$nii"
    DIR=" /home/$USER/Program/tvhelper-1.1.5"
    
    
    tv ()	{
    
        echo -en "Downloading ..."
        wget $uri
        tar -xzf $ni -C ~/Program
        wget $urii
        tar -xjf $nii
        mv -f TVHelper.c $DIR/src
        rm $ni $nii
    }
    
    inst ()  {
    
        cd  $DIR
        ./configure --with-player=vlc --with-playerpath=/usr/bin/vlc 
        make 
        sudo make install
    }
    
    if  [ -e  ~/Program/tvhelper-1.1.5 ];then inst
    elif  [ -e ~/Program ];then tv
    else
        mkdir ~/Program; tv ;inst
    fi per-1.1.5.tar.gz
    sleep 5 
    
    ########################################################################
    #Инсталиране на Skype за 32 бит!
    pks="/home/$USER/Programs/skype-2.1.0.81-suse.i586.rpm"
    si="uname -i"
    
    if [ $si = "x86_64" ];then sudo zypper in -y skype 
    
    else [ !-e "$pks" ]
        then
             wget -q http://www.skype.com/go/getskype-linux-beta-suse
             sudo zypper in -y ~/skype-2.1.0.81-suse.i586.rpm
    	 rm ~/skype-2.1.0.81-suse.i586.rpm
             
    fi
    #######################################################################
    
    #Инсталиране на прог. проверяваща gmail
    wget http://gmail-plasmoid.googlecode.com/files/gmail-plasmoid-0.7.15.plasmoid
    plasmapkg -i gmail-plasmoid-0.7.15.plasmoid
    exit
    openSUSE Tumbleweed KDE
    Linux user #543309
    http://cazadordevarna-kennel.com/suse/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •