how to assign file name with full path to a variable in bash script

suppose i opened my file manager nemo and select a file named “abc” so in the location bar it shows media/myuser/folder1/subfoler/ and the selected file name is abc How can assign the selected (highlighted) file name with full path in a variable in my bash script (please note this file is not in home directory) anybody can help me please

Bash convert string to integer

I am new at bash scripting, I need to write a script capable of taking a file with a given text (written numbers and arithmetic operators) and transform these words into integers and ex: +, -, *, %.

The example that I have is a file with the following text : one two three plus nine eight seven. The script needs to change these words and transform them to 123 + 987, then printing the result 1110.

So far I have this, but I am not sure how to compare each word in the file to the ones in my code with the correct values to be able to do the operations.

#!/bin/bash  fileCal="$  1"  #file in_calc is entered  d=( ["zero"]="0" ["one"]="1" ["two"]="2" ["three"]"3" ["four"]="4" ["five"]"5" ["six"]="6" ["seven"]="7" ["eight"]="8" ["nine"]="9" ["plus"]="+" ["minus"]="-"  ["times"]="\*" ["div"]="/" ["modulo"]="%")   if [ "$  #" == 0 ]; then     echo $  error elif [ -f $  fileCal ]; then     read -a $  fileCal  fi 

Process monitor script bash

I am using below script to monitor some processes on linux and restart if process is down and send email.

I want to add below improvements in this script, I need help in that case.

  • Seconds to wait between attempts to restart service
  • Number of attempts before giving up
  • Check interval in seconds
  • Generate logs in case of events.

Current script:

###edit the following export smtp=smtprelay.domainname.com:25 service=splunk email=mailID@xyz.com ###You can provide multiple mail ID's above in email variable separated by commas ###stop editing  host=`hostname -f` if (( $  (ps -ef | grep -v grep | grep $  service | wc -l) > 2 )) then echo "$  service is running" else /opt/splunk/bin/$  service restart if (( $  (ps -ef | grep -v grep | grep $  service | wc -l) > 2 )) then subject="$  service at $  host has been started" echo "$  service at $  host wasn't running and has been started" | mailx -s "$  subject" $  email else subject="$  service at $  host is not running" echo "$  service at $  host is stopped and cannot be started!!!" | mailx -s "$  subject" $  email fi fi 

Check and install multiple packages if not installed – using bash

I need to Bash script which will install few packages. For Example: I need install packages: Molecule and Ansible

Bash script should do it and I need it for Ubuntu/Debian:

If Molecule exist > print "Molecule Installed" else apt-get install Molecule then if Ansible exist > print "Ansible installed" else apt-get install Ansible 

Can you tell me how will look script in bash, which will contain the above instructions?

Thank you in advance!

UPDATED: Bash script to setup new Debian installs

I have this bash script I’ve been working on and I have updated it, I was hoping for some advice and/or input on the code?

This script is run directly after a fresh install of Debian, to do:

  • Sets up syntax highlighting in Nano,
  • Sets up iptables,
  • Sets up ssh,
  • Sets up custom bashrc files
  • ls colors
  • Creates users on the system if needed,
  • Checks if user has a password set and sets it if not,
  • Installs non-free firmware and sets up apt with Virtualbox deb file and multimedia deb in sources.list.
  • Installs video and audio codecs, players and related.
  • Sets up flash for Mozilla Firefox and creates a cron for weekly updates.
  • It updates the system.

There was mention of debconf but I’ve never heard about that.

Could you add some features to the program that are practical, convenient or cool for setting up new installs?

Is there anything in the program that I don’t need?

Here is the code:

#!/bin/bash -x  shopt -s -o nounset ####### Catch signals that could stop the script trap : SIGINT SIGQUIT SIGTERM #################################  #################### Setup system to send email with your google/gmail account and sendmail ############################## ################### TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO ##############################   # Configuring Gmail as a Sendmail email relay # # #Introduction # #In this configuration tutorial we will guide you through the process of configuring sendmail to be an email relay for your gmail or google apps account.  #This allows #you to send email from your bash scripts, hosted website or from command line using mail command.  #Other examples where you can utilize this setting is for a #notification purposes such or failed backups etc. #Sendmail is just one of many utilities which can be configured to rely on gmail account where the others include #postfix, exim , ssmpt etc.  #In this tutorial we will use Debian and sendmail for this task. #Install prerequisites # ## CODE:apt-get install sendmail mailutils sendmail-bin  # #Create Gmail Authentication file # ## CODE:mkdir -m 700 /etc/mail/authinfo/ ## CODE:cd /etc/mail/authinfo/ # #next we need to create an auth file with a following content. File can have any name, in this example the name is gmail-auth: # # CODE: printf 'AuthInfo: "U:root" "I:YOUR GMAIL EMAIL ADDRESS" "P:YOUR PASSWORD"\n' > gmail-auth # #Replace the above email with your gmail or google apps email. # #Please note that in the above password example you need to keep 'P:' as it is not a part of the actual password. # #In the next step we will need to create a hash map for the above authentication file: # ## CODE:makemap hash gmail-auth < gmail-auth # #Configure your sendmail  # #Put bellow lines into your sendmail.mc configuration file right above first "MAILER" definition line: ###################################################### # #define(`SMART_HOST',`[smtp.gmail.com]')dnl #define(`RELAY_MAILER_ARGS', `TCP $  h 587')dnl #define(`ESMTP_MAILER_ARGS', `TCP $  h 587')dnl #define(`confAUTH_OPTIONS', `A p')dnl #TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl #define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl #FEATURE(`authinfo',`hash -o /etc/mail/authinfo/gmail-auth.db')dnl ############################################################################################################################################################# #Do not put the above lines on the top of your sendmail.mc configuration file ! # #In the next step we will need to re-build sendmail's configuration. To do that execute: # ## CODE: make -C /etc/mail # #Reload sendmail service: # # CODE:/etc/init.d/sendmail reload # #and you are done. #Configuration test # #Now you can send an email from your command line using mail command: # # CODE: echo "Just testing my sendmail gmail relay" | mail -s "Sendmail gmail Relay" "This email address is being protected from spambots." #  ######################### Trap signals and exit to send email on it ####################################################### #trap 'echo "Subject: Program finsihed execution" | sendmail -v "This email address is being protected from spambots."' exit # It will mail on normal exit #trap 'echo "Subject: Program interrupted" | /usr/sbin/sendmail -v "This email address is being protected from spambots."' INT HUP # it will mail on interrupt or hangup  of the process  ################ Enter the working directory where all work happens ########################################## cd "$  WORK_DIR" | { echo "cd $  WORK_DIR failed"; exit 127; }  # redirect all errors to a file                                                                    #### MUNA setja þetta í sshd_config="#HISTAMIN98" if [ -w /tmp/svaka ] then     exec 2>debianConfigVersion5.3__ERRORS__.txt else     echo "can't write error file!"     exit 127 fi ##################################################################################################### TODO exec 3>cpSuccessCodes.txt ##  #############################################################################################################   SCRIPTNAME=$  (basename "$  0")  if [ "$  UID" != 0 ]     then     echo "This program should be run as root, exiting! now....."     sleep 3     exit 1 fi  if [ "$  #" -eq 0 ] then     echo "RUN AS ROOT...Usage if you want to create users:...$  SCRIPTNAME USER_1 USER_2 USER_3 etc."     echo "If you create users they will be set with a semi strong password which you need to change later as root with the passwd command"     echo     echo     echo "#################### ↓↓↓↓↓↓↓↓↓↓↓ OR ↓↓↓↓↓↓↓↓↓↓ #############################"     echo     echo     echo "RUN AS ROOT...Usage without creating users: $  SCRIPTNAME"     echo     sleep 10  fi  echo "Here starts the party!" echo "Setting up server..........please wait!!!!!" sleep 3  ### ↓↓↓↓ Initialization of VARIABLES............NEXT TIME USE "declare VARIABLE" ↓↓↓↓↓↓↓↓↓↓ ##### OAUTH_TOKEN=d6637f7ccf109a0171a2f55d21b6ca43ff053616 WORK_DIR=/tmp/svaka BASHRC=.bashrc NANORC=.nanorc BASHRCROOT=.bashrcroot SOURCE=sources.list PORT=""  ########### Commands PWD=`pwd`  #-----------------------------------------------------------------------↓↓ export DEBIAN_FRONTEND=noninteractive #-----------------------------------------------------------------------↑↑  ############################### make all files writable, executable and readable in the working directory######### if ! chown -R root:root "$  WORK_DIR" then     echo "chown WORK_DIR failed"     exit 127 fi  if ! chmod -R 750 "$  WORK_DIR" then     echo "chmod WORK_DIR failed"     exit 127 fi  ############################ Check if files exist and are writable #########################################  if [[ ! -f "$  WORK_DIR"/.bashrc && ! -w "$  WORK_DIR"/.bashrc ]] then     echo "missing .bashrc file or is not writable.. exiting now....." && { exit 127; } fi if [[ ! -f "$  WORK_DIR"/.nanorc && ! -w "$  WORK_DIR"/.nanorc ]] then     echo "missing .nanorc file or is not writable.. exiting now....." && { exit 127; } fi     if [[ ! -f "$  WORK_DIR"/.bashrcroot && ! -w "$  WORK_DIR"/.bashrcroot ]] then     echo "missing .bashrcroot file or is not writable..exiting now....." && { exit 127; } fi if [[ ! -f "$  WORK_DIR"/sources.list && ! -w "$  WORK_DIR"/sources.list ]] then     echo "missing sources.list file or is not writable..exiting now....." && { exit 127; } fi  ################### Check if PORT is set and if sshd_config is set and if PORT is set in iptables #################### if [[ $  PORT == "" ]] && [[ ! `grep "#HISTAMIN98" /etc/ssh/sshd_config` ]] && [[ ! `grep $  PORT /etc/iptables.up.rules` ]] then     echo -n "Please select/provide the port-number for ssh in iptables setup or sshd_config file:"     read port ### when using the "-p" option then the value is stored in $  REPLY     PORT=$  port fi   ################ Creating new users #####################1  creatingNewUsers() {     for name in "$  @"     do         if id -u "$  name" #>/dev/null 2>&1         then             echo "User: $  name exists....setting up now!"             sleep 2         else             echo "User: $  name does not exists....creating now!"                         useradd -m -s /bin/bash "$  name" #>/dev/null 2>&1             sleep 2         fi     done }  ###########################################################################3 ################# GET USERS ON THE SYSTEM ###################################  prepare_USERS.txt() {     awk -F: '$  3 >= 1000 { print $  1 }' /etc/passwd > "$  WORK_DIR"/USERS.txt      chmod 750 "$  WORK_DIR"/USERS.txt     if [[ ! -f "$  WORK_DIR"/USERS.txt && ! -w "$  WORK_DIR"/USERS.txt ]]     then         echo "USERS.txt doesn't exist or is not writable..exiting!"         sleep 3         exit 127     fi #   if [[ ! "$  @" == "" ]] #   then #        for user in "$  @" #        do #            echo "$  user" >> /tmp/svaka/USERS.txt || { echo "writing to USERS.txt failed"; exit 127; } #        done #    fi } ########################################## user passwords2 userPasswords() {     if [[ ! -f "$  WORK_DIR"/USERS.txt && ! -w "$  WORK_DIR"/USERS.txt ]]     then         echo "USERS.txt doesn't exist or is not writable..exiting!"         sleep 3         exit 127     fi     while read user     do         if [ "$  user" = root ]         then             continue         fi         if [[ $  (passwd --status "$  user" | awk '{print $  2}') = NP ]] || [[ $  (passwd --status "$  user" | awk '{print $  2}') = L ]]          then             echo "$  user doesn't have a password."             echo "Changing password for $  user:"             sleep 3             echo $  user:$  user"YOURSTRONGPASSWORDHERE12345Áá" | /usr/sbin/chpasswd             if [ "$  ?" = 0 ]                 then                 echo "Password for user $  user changed successfully"                 sleep 3             fi         fi     done < "$  WORK_DIR"/USERS.txt }  ################################################ setting up iptables ####################3 setUPiptables() {     #if ! grep -e '-A INPUT -p tcp --dport 80 -j ACCEPT' /etc/iptables.test.rules     if [[ `/sbin/iptables-save | grep '^\-' | wc -l` > 0 ]]     then         echo "Iptables already set, skipping..........!"         sleep 2     else         if [ "$  PORT" = "" ]         then             echo "Port not set for iptables, setting now......."             echo -n "Setting port now, insert portnumber: "             read port             PORT=$  port         fi         if [ ! -f /etc/iptables.test.rules ]         then             touch /etc/iptables.test.rules         else             cat /dev/null > /etc/iptables.test.rules         fi          cat << EOT >> /etc/iptables.test.rules         *filter          # Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0         -A INPUT -i lo -j ACCEPT         -A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT          # Accepts all established inbound connections         -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT          # Allows all outbound traffic         # You could modify this to only allow certain traffic         -A OUTPUT -j ACCEPT          # Allows HTTP and HTTPS connections from anywhere (the normal ports for websites)         -A INPUT -p tcp --dport 80 -j ACCEPT         -A INPUT -p tcp --dport 443 -j ACCEPT          # Allows SSH connections         # The --dport number is the same as in /etc/ssh/sshd_config         -A INPUT -p tcp -m state --state NEW --dport $  PORT -j ACCEPT          # Now you should read up on iptables rules and consider whether ssh access         # for everyone is really desired. Most likely you will only allow access from certain IPs.          # Allow ping         #  note that blocking other types of icmp packets is considered a bad idea by some         #  remove -m icmp --icmp-type 8 from this line to allow all kinds of icmp:         #  https://security.stackexchange.com/questions/22711         -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT          # log iptables denied calls (access via dmesg command)         -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7          # Reject all other inbound - default deny unless explicitly allowed policy:         -A INPUT -j REJECT         -A FORWARD -j REJECT          COMMIT EOT         sed "s/^[ \t]*//" -i /etc/iptables.test.rules ## remove tabs and spaces         /sbin/iptables-restore < /etc/iptables.test.rules || { echo "iptables-restore failed"; exit 127; }         /sbin/iptables-save > /etc/iptables.up.rules || { echo "iptables-save failed"; exit 127; }         printf "#!/bin/bash\n/sbin/iptables-restore < /etc/iptables.up.rules" > /etc/network/if-pre-up.d/iptables ## create a script to run iptables on startup         chmod +x /etc/network/if-pre-up.d/iptables || { echo "chmod +x failed"; exit 127; }     fi }  ###################################################33 sshd_config4 setUPsshd() {     if grep "Port $  PORT" /etc/ssh/sshd_config     then         echo "sshd already set, skipping!"         sleep 3     else          if [ "$  PORT" = "" ]         then             echo "Port not set"             sleep 3             exit 12         fi         users=""         /bin/cp -f "$  WORK_DIR"/sshd_config /etc/ssh/sshd_config         sed -i "s/Port 22300/Port $  PORT/" /etc/ssh/sshd_config         for user in `awk -F: '$  3 >= 1000 { print $  1 }' /etc/passwd`         do             users+="$  {user} "         done         if grep "AllowUsers" /etc/ssh/sshd_config         then             sed -i "/AllowUsers/c\AllowUsers $  users" /etc/ssh/sshd_config         else             sed -i "6 a \             AllowUsers $  users" /etc/ssh/sshd_config         fi          chmod 644 /etc/ssh/sshd_config         /etc/init.d/ssh restart     fi }  #################################################3333 Remove or comment out DVD/cd line from sources.list5 editSources() {     if grep '^# *deb cdrom:\[Debian' /etc/apt/sources.list     then         echo "cd already commented out, skipping!"     else         sed -i '/deb cdrom:\[Debian GNU\/Linux/s/^/#/' /etc/apt/sources.list     fi }  ####################################################33 update system6  updateSystem() {     apt update && apt upgrade -y }   ###############################################################7 ############################# check if programs installed and/or install checkPrograms() {     if [ ! -x /usr/bin/git ] && [ ! -x /usr/bin/wget ] && [ ! -x /usr/bin/curl ] && [ ! -x /usr/bin/gcc ] && [ ! -x /usr/bin/make ]     then         echo "Some tools with which to work with data not found installing now......................"         sleep 2         apt install -y git wget curl gcc make     fi }  #####################################################3 update sources.list and install software ############################################################ updateSources_installSoftware() {     if grep "deb http://www.deb-multimedia.org" /etc/apt/sources.list     then         echo "Sources are setup already, skipping!"     else         /bin/cp -f "$  WORK_DIR"/"$  SOURCE" /etc/apt/sources.list || { echo "cp failed"; exit 127; }         chmod 644 /etc/apt/sources.list         wget http://www.deb-multimedia.org/pool/main/d/deb-multimedia-keyring/deb-multimedia-keyring_2016.8.1_all.deb || { echo "wget failed"; exit 127; }         dpkg -i deb-multimedia-keyring_2016.8.1_all.deb         wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -         updateSystem || { echo "update system failed"; exit 127; }         apt install -y vlc vlc-data browser-plugin-vlc mplayer youtube-dl libdvdcss2 libdvdnav4 libdvdread4 smplayer mencoder build-essential \         gstreamer1.0-libav gstreamer1.0-plugins-bad gstreamer1.0-vaapi lame libfaac0 aacskeys libbdplus0 libbluray1 audacious audacious-plugins \         deadbeef kodi audacity cinelerra handbrake-gtk ffmpeg amarok k3b || { echo "some software failed to install!!!!!"; echo "some software failed to install"; \         sleep 10 }         ########################## Install flash in Mozilla Firefox ############################################         wget https://raw.githubusercontent.com/cybernova/fireflashupdate/master/fireflashupdate.sh || { echo "wget flash failed"; sleep 4; exit 127; }         chmod +x fireflashupdate.sh || { echo "chmod flash failed"; sleep 4; exit 127; }         ./fireflashupdate.sh         ######################### Setup the update tool to update flash weekly ###################################3         chown root:root fireflashupdate.sh || { echo "chown flash failed"; sleep 4; exit 127; }         /bin/mv fireflashupdate.sh /etc/cron.weekly/fireflashupdate || { echo "mv flash script failed"; sleep 4; exit 127; }      fi }  ###############################################33  SETUP PORTSENTRY ############################################################ ##############################################3                     ############################################################33  setup_portsentry() {     if  ! grep -q '^TCP_PORTS="1,7,9,11,15,70,79' /etc/portsentry/portsentry.conf     then         if [[ -f /etc/portsentry/portsentry.conf ]]         then             /bin/mv /etc/portsentry/portsentry.conf /etc/portsentry/portsentry.old         fi         if [[ ! -x /usr/sbin/portsentry ]]         then             apt install -y portsentry logcheck             /bin/cp -f "$  WORK_DIR"/portsentry.conf /etc/portsentry/portsentry.conf || { echo "cp portsentry failed"; exit 127; }             /usr/sbin/service portsentry restart || { echo "service portsentry restart failed"; exit 127; }         fi     fi }  ###############################################################################################################################33 #####################################################3 run methods here↓   ###################################################3 #####################################################                      ################################################### if [[ ! "$  @" == "" ]] then     creatingNewUsers "$  @" fi prepare_USERS.txt userPasswords setUPiptables setUPsshd editSources updateSystem #setup_portsentry    ######3 NEEDS WORK ################################## checkPrograms updateSources_installSoftware ###########################################################################################################            #####3## ##############################################################################################################3Methods ##########################################3 Disable login for www-data ######### passwd -l www-data #################################### firmware apt install -y firmware-linux-nonfree firmware-linux apt install -y firmware-linux-free intel-microcode sleep 3 ################ NANO SYNTAX-HIGHLIGHTING #####################3 if [ ! -d "$  WORK_DIR"/nanorc  ] then     if [ "$  UID" != 0 ]     then         echo "This program should be run as root, goodbye!"         exit 127      else         echo "Setting up Nanorc file for all users....please, wait!"         if [[ $  PWD == "$  WORK_DIR" ]]         then             echo "Program is in WORK_DIR...success!......."         else             echo "not in WORK_DIR...TRYING 'cd WORK_DIR'"             cd "$  WORK_DIR" || { echo "cd failed"; exit 127; }         fi         git clone https://$  OAUTH_TOKEN:x-auth-basic@github.com/gnihtemoSgnihtemos/nanorc || { echo "git failed"; exit 127; }         chmod 755 "$  WORK_DIR"/nanorc || { echo "chmod nanorc failed"; exit 127; }         cd "$  WORK_DIR"/nanorc || { echo "cd failed"; exit 127; }         make install-global || { echo "make failed"; exit 127; }         /bin/cp -f "$  WORK_DIR/$  NANORC" /etc/nanorc || { echo "cp failed"; exit 127; }         chown root:root /etc/nanorc || { echo "chown failed"; exit 127; }         chmod 644 /etc/nanorc || { echo "chmod failed"; exit 127; }         if [ "$  ?" = 0 ]         then             echo "Implementing a custom nanorc file succeeded!"         else             echo "Nano setup DID NOT SUCCEED!"             exit 127         fi         echo "Finished setting up nano!"     fi fi  ################ LS_COLORS SETTINGS and bashrc file for all users ############################# if ! grep 'eval $  (dircolors -b $  HOME/.dircolors)' /root/.bashrc then     echo "Setting root bashrc file....please wait!!!!"     if /bin/cp -f "$  WORK_DIR/$  BASHRCROOT" "$  HOME"/.bashrc     then         echo "Root bashrc copy succeeded!"         sleep 2     else         echo "Root bashrc cp failed, exiting now!"         exit 127     fi     chown root:root "$  HOME/.bashrc" || { echo "chown failed"; exit 127; }     chmod 644 "$  HOME/.bashrc" || { echo "failed to chmod"; exit 127; }     wget https://raw.github.com/trapd00r/LS_COLORS/master/LS_COLORS -O "$  HOME"/.dircolors || { echo "wget failed"; exit 127; }     echo 'eval $  (dircolors -b $  HOME/.dircolors)' >> "$  HOME"/.bashrc || { echo "echo dircolors -b....to bashrc failed"; exit 127; } fi while read user do     if [ "$  user" = root ]     then         continue     fi      sudo -i -u "$  user" user="$  user" WORK_DIR="$  WORK_DIR" BASHRC="$  BASHRC" bash <<'EOF'     if grep 'eval $  (dircolors -b $  HOME/.dircolors)' "$  HOME"/.bashrc     then         :     else         echo "Setting users=Bashrc files!"         if /bin/cp -f "$  WORK_DIR"/"$  BASHRC" "$  HOME/.bashrc"         then             echo "Copy for $  user (bashrc) succeeded!"             sleep 2         else             echo "Couldn't cp .bashrc for user $  user"             exit 127         fi         chown $  user:$  user "$  HOME/.bashrc" || { echo "chown failed"; exit 127; }         chmod 644 "$  HOME/.bashrc" || { echo "chmod failed"; exit 127; }         wget https://raw.github.com/trapd00r/LS_COLORS/master/LS_COLORS -O "$  HOME"/.dircolors || { echo "wget failed"; exit 127; }         echo 'eval $  (dircolors -b $  HOME/.dircolors)' >> "$  HOME"/.bashrc     fi EOF done < "$  WORK_DIR"/USERS.txt  echo "Finished setting up your system!" sleep 2 ############ Give control back to these signals trap SIGINT SIGQUIT SIGTERM ############################ cd $  HOME || { echo "cd $  HOME failed"; exit 155; } ######### REmember to uncomment below echo to remove the install files after installation/configuration.......↓↓↓ echo rm -rf /tmp/svaka || { echo "Failed to remove the install directory!!!!!!!!"; exit 155; } exit 0 

How to output one number few times with spaces in one line via bash

How to output one number few times with spaces in one line via bash

I have

a=5 b=10 

I should output 5 times number 10 with using of variables and with spaces Also, i should capture this in variable

For example, i have to receive this

10 10 10 10 10

And it should be variable, it can be array. But after echo $ c, i should receive 10 10 10 10 10

How to do it ?

Bash Script Help

I’m trying to alter this script below to rename a hostname once ran. The naming format should be first name of the user account first initial of the last name of the user account a dash then the serial number of the machine.

Should look like this: Johns-c01jt4i394

Script to alter is below:

#!/bin/sh  #gets current logged in user getUser=$  (ls -l /dev/console | awk '{ print $  3 }')  serial=(ioreg -l | awk '/IOPlatformSerialNumber/ { print $  4;}’)  #gets named firstInitial=$  (finger -s $  getUser | head -2 | tail -n 1 | awk '{print tolower($  2)}' | cut -c 1) lastName=$  (finger -s $  getUser | head -2 | tail -n 1 | awk '{print tolower($  3)}') computerName=$  firstInitial$  lastName”-$  serial”  #set all the name in all the places scutil --set ComputerName "$  computerName" scutil --set LocalHostName "$  computerName" scutil --set HostName "$  computerName" 

Two different file references in bash for loops simultaneously

Is there a way to use two different file references in for loops simultaneously? Something like:

for file in file1 file2 file3; for name in name1 name2 name3 do   awk 'FNR==NR{a[$  1];next};($  1 in a)' $  {file}.txt $  {name}.txt > $  {name}_extract.txt done 

I tried also with a nested for loop but didn’t work:

for file in file1 file2 file3   for name in name1 name2 name3   do     awk 'FNR==NR{a[$  1];next};($  1 in a)' $  {file}.txt $  {name}.txt > $  {name}_extract.txt   done done 

Is it possible to build a .deb package of a folder full of python and bash scripts?

I have a folder full of scripts that I use as functions on other scripts… I usually save these scripts on /usr/local/bin and give them execution permission for all users so I can run those scripts with different users. I know that I can just create a script that synchronizes the scripts’ folder with /usr/local/bin, but I was wondering if I could also create a deb package of all my scripts in a way that the dependencies of these scripts will be installed along with a deb package that I’ve created (with apt-get -f install). Is it possible? What are the main procedures I need to do in order to build a deb package that will get my scripts on PATH and install their dependencies?

Преобразование Батника в bash script

У меня есть скрипты и я хотел бы чтобы их можно было запустить из-под линукса:

node site/index/_tools/processes/build-index -local && gulp build-index -local  node site/book/_tools/processes/build-books -local gulp build-books -local  node site/must-have/_tools/processes/build-must-have -local && gulp move must-have -local && build-index && build-books