ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login
    1. Topics
    2. Tags
    3. bash
    Log in to post
    • All categories
    • scottalanmillerS

      Clean a Linux or UNIX Text File to Strip Hidden Characters

      Watching Ignoring Scheduled Pinned Locked Moved IT Discussion linux unix text bash string
      3
      1 Votes
      3 Posts
      2k Views
      scottalanmillerS

      @CCWTech said in Clean a Linux or UNIX Text File to Strip Hidden Characters:

      @scottalanmiller Great, but can you explain the syntax of the command?

      trim anything accept characters 11, 12, or 40-176. The acceptable character ranges.

    • JaredBuschJ

      beyond bash shell scripting, what language should I use

      Watching Ignoring Scheduled Pinned Locked Moved Unsolved IT Discussion bash scripting linux fedora debian python go
      20
      1 Votes
      20 Posts
      3k Views
      scottalanmillerS

      @jaredbusch said in beyond bash shell scripting, what language should I use:

      @scottalanmiller said in beyond bash shell scripting, what language should I use:

      @jaredbusch said in beyond bash shell scripting, what language should I use:

      @stacksofplates said in beyond bash shell scripting, what language should I use:

      @jaredbusch said in beyond bash shell scripting, what language should I use:

      @scottalanmiller said in beyond bash shell scripting, what language should I use:

      Go is great as a language. But like Ruby, not installed generally. And fewer resources. If it was a greenfield new OS, yeah, Go for sure. But for practical reasons, Python I think.

      As these are systems that I control, there is no reason Go cannot be installed.

      Between your comments and prior ones from @stacksofplates I think I might try Go in order to learn it.

      You normally wouldn't install it anyway as it's not a scripting language. You'd just compile your binary and ship that to your systems.

      I completely misunderstood that about Go. Okay, I will do a bit of checking and decide what I want to do.

      oh sorry, I figured you knew. That's why I never look at it, I don't want to deal with binaries in that way. But nothing wrong with that. Write it on your machine at home, compile, ship binary. Works just fine.

      As fixed tasks, this is not a bad solution. So I will keep it in mind.

      Right, no big deal in this case.

    • EddieJenningsE

      Unifi Controller Installer Script for Ubuntu 21.04

      Watching Ignoring Scheduled Pinned Locked Moved IT Discussion bash unifi controller ubuntu 21.04 mongodb scripting
      7
      5 Votes
      7 Posts
      3k Views
      stacksofplatesS

      @dbeato said in Unifi Controller Installer Script for Ubuntu 21.04:

      @voip_n00b said in Unifi Controller Installer Script for Ubuntu 21.04:

      @stacksofplates docker is worse than reddit. I can’t believe you would suggest such hot garbage.

      How is it garbage @VoIP_n00b ? It is quite possible if someone wants to run their Controller as a container. I am not sure why you are also comparing Reddit with Docker, what is the comparison?

      I think it's an attempt at trolling.

    • L

      Send CSV file to Slack Channel by bash script through Webhook

      Watching Ignoring Scheduled Pinned Locked Moved IT Discussion slack csv bash script webhook api
      6
      1 Votes
      6 Posts
      3k Views
      stacksofplatesS

      @pete-s said in Send CSV file to Slack Channel by bash script through Webhook:

      @laksh1999 said in Send CSV file to Slack Channel by bash script through Webhook:

      @pete-s said in Send CSV file to Slack Channel by bash script through Webhook:

      @laksh1999 said in Send CSV file to Slack Channel by bash script through Webhook:

      Hi
      I am trying to send the assigned tickets in the queue as .csv file to the slack channel. I am able to download the .csv file in the dev desktop through bash script but unable to send that file to the Slack Channel.

      Anyone have tried this before?

      I have checked this

      https://api.slack.com/methods/files.upload

      I have only Webhook URL no other token is there with me as per the suggestion in the above link.

      You must have a token or some kind of authentication, otherwise anyone would be spam slack with files.

      Also the function you are looking at is not a webhook. Webhooks are triggered by an event. And they cause a http request to be sent.

      I accept with your point the csv file which i download is authenticated with the kerberos only.So is that enough and send the .csv file to the slack channel through the webhook ?

      @stacksofplates maybe you can offer some insight?

      At the bottom of the upload API page they give you an example of what you need. You need your API token and the channel ID(s) that you want to send the data to.

      curl -F [email protected] -F "initial_comment=Shakes the cat" -F channels=C024BE91L,D032AC32T -H "Authorization: Bearer xoxa-xxxxxxxxx-xxxx" https://slack.com/api/files.upload

    • JaredBuschJ

      Redirecting feedback from Linux command

      Watching Ignoring Scheduled Pinned Locked Moved Unsolved IT Discussion linux bash scripting redirect
      7
      0 Votes
      7 Posts
      940 Views
      1

      @JaredBusch said in Redirecting feedback from Linux command:

      @Pete-S Pretty much what I do not want is the status bar from these two commands.

      fwconsole ma upgradeall

      fwconsole chown

      Well, use grep to match for the progress bar then.

      First output stderr to a file and look in the file.

      I don't know how the progress bar looks when it's output as a stream of characters.
      I'm guessing every update is something like

      3076094/3076094 [===========>-------------] 60%<CR>

      In that case grep for every line that doesn't contain a [ followed by a number of =, > or - and finally a ].

      So something like:

      grep -v '\[[=->]+\\]'

      Or maybe even better:

      grep -v '\[[=->]{28}\\]'

      Above assuming there are always 28 characters inside the brackets in the progress bar.

      PS.
      Funny thing but there seems to be a bug in the forum software.
      I had to use an extra backslash to get the above regex look right \[[=->]+\\\] instead of \[[=->]+\\]
      They look right in the preview though.

    • EddieJenningsE

      Script for Creating VMs from Template VM in KVM

      Watching Ignoring Scheduled Pinned Locked Moved IT Discussion linux kvm bash automation
      9
      0 Votes
      9 Posts
      1k Views
      1

      @EddieJennings said in Script for Creating VMs from Template VM in KVM:

      @travisdh1 said in Script for Creating VMs from Template VM in KVM:

      @EddieJennings said in Script for Creating VMs from Template VM in KVM:

      @Pete-S said in Script for Creating VMs from Template VM in KVM:

      Not the exactly the same thing but you might want to look into how to create a VM from scratch.
      Meaning a script that will set up a VM with vCPU, memory, storage, network etc and then boot it from iso and have it do an unattended install, create what users you want and install the packages you need.

      That's one of the next things I'm looking into.

      @EddieJennings Also remember about things like kickstart in RedHat based operating systems. In Fedora/CentOS/RHOS you can use a kickstart file to automatically select all the install time options for the OS. A short time later you've got a fresh server and all the time it took you to setup was running the creation script on your hypervisor.

      One of the things I'll need to figure out going the Kickstart route is setting the hostname what I want it to be at the time of installation. Likely not difficult to do, I just have to figure it out. Or perhaps, I can just truly take the approach of just making a clean minimal install, and then later configure to whatever specific thing I'm wanting the VM to do for my lab / testing.

      Inside the kickstart file you'll find something like this:

      network --hostname=centos8-4.example.com

      We use debian as our goto and then it's called a preseed file. The only real thing that can be tricky is to tell the installation what kickstart/preseed file you want to use. You can do it in different ways. If you don't want to rely on dhcp/tftp/pxe etc you can roll your own iso file. I think the kickstart file can also be mounted as a drive that the installation will detect when it starts.

      I think the best approach is to make an automated installation with same basic settings and some of those will get changed later in the installation. For example you can use a fixed hostname that is later changed from ansible.

    • JaredBuschJ

      VitalPBX setup script on Vultr

      Watching Ignoring Scheduled Pinned Locked Moved Solved IT Discussion vitalpbx vultr linux shell bash scripting
      5
      0 Votes
      5 Posts
      820 Views
      JaredBuschJ

      e0defcac-7cf0-4601-8e04-178a60ea74ed-image.png

    • 1

      Searching for text in file

      Watching Ignoring Scheduled Pinned Locked Moved Solved IT Discussion linux grep bash
      7
      0 Votes
      7 Posts
      902 Views
      dafyreD

      @Obsolesce said in Searching for text in file:

      @dafyre said in Searching for text in file:

      @Pete-S said in Searching for text in file:

      If you have a text file that looks like this:

      start_folder='/folder1/abc.txt' iterations='123' passphrase='xyz' last_command='invoke' return_value='0'

      How can you pick out just xyz when looking for "passphrase"?

      I know grep will get me the line but what should I use if I want just a part of the line?
      Can it be done in one command or do I have to pipe several together?

      If you the text has a character that would be a good delimiter, you can pipe grep to cut... ie:

      cat myfile.txt|grep "iterations"|cut -d '=' -f 2 Output: '123'

      the -f # is which column you want.

      There may be other ways to do it, but that's the first way I can think of.

      You can specify a file with grep, no need to pipe in from cat.

      This is true! I always seem to get it backwards when I do that, so i just cat $thefile | grep | blah ... Cuts down on frustration, ha ha.

    • scottalanmillerS

      What is a For Loop

      Watching Ignoring Scheduled Pinned Locked Moved Developer Discussion loops bash
      21
      3 Votes
      21 Posts
      2k Views
      ObsolesceO

      I did some experimenting... but it's not always the case, it depends on what you are doing. But doing this with simple counting results:

      b3b9a87e-cb8d-4e6f-8edb-dd29ffc719b2-image.png

      And for fun lol....

      eb24b287-1c66-4c93-8949-85d9f083eab7-image.png

    • wirestyle22W

      Script to Move and Decrypt Files in a Specified Directory

      Watching Ignoring Scheduled Pinned Locked Moved IT Discussion bash gpg
      13
      0 Votes
      13 Posts
      1k Views
      wirestyle22W

      This week was a learning experience.

      #!/usr/bin/env bash source "/home/datatransfer/company/master.sh" encryptedFolderPath="/home/datatransfer/company/in /" decryptedFolderPath="/home/datatransfer/company/out" archiveFolderPath="/home/datatransfer/company/archive" for i in $(ls $encryptedFolderPath.pgp) do gpg --batch --passphrase $PASS --list-only --list-packets --yes $i | grep -q "encrypted" if [ $? != 0 ]; then echo "$i is not a pgp file" continue fi v=${i%.} encryptedFile="$v" fileName=${encryptedFile##/} timeNow=$(date +%Y%m%d%H%M) extension=${fileName##.} newFileName=${fileName%.*} fileWithTimestamp="$newFileName""_""$timeNow.$extension" gpg --batch –passphrase $PASS --yes --decrypt $i > $decryptedFolderPath/$fileWithTimestamp ls -lr $decryptedFolderPath/$fileWithTimestamp if [ $? != 0 ]; then echo "$fileWithTimestamp is not a readable file" continue fi mv $i $archiveFolderPath done

      Thanks to @scottalanmiller @stacksofplates and my friend Erik

    • JaredBuschJ

      bash script help splitting string

      Watching Ignoring Scheduled Pinned Locked Moved Unsolved IT Discussion bash scripting arrays
      3
      0 Votes
      3 Posts
      642 Views
      JaredBuschJ

      @matteo-nunziati said in bash script help splitting string:

      try this:

      # initializing agi variables declare -a array while read -e ARG && [ "$ARG" ] ; do array=(` echo "$ARG" | sed -e 's/://'`) export ${array[0]}=${array[@]:1} #next added line for debug only. comment this out in prod. echo "${array[0]}=${array[@]:1}" done

      if you want to "slice" an array use the syntax: ${array[@]:from:to}, not providing the 'to' arg means go up to the end of array.
      source here.

      Almost right. Because of the export command parsing spaces, I needed to stick it in a variable first.

      # Variable to hold the details for the log file DUMPARG=" Begin Argument dump:\n" # Create an Array to hold the results of the loop declare -a array # Loop through the AGI variables while read -e ARG && [ "$ARG" ] ; do # Dump them into an array, after removing the : array=(` echo $ARG | sed -e 's/://'`) # take the array and create a variable from the first element put the rest as the value # value must be put into a holding variable to parse correctly by the export command val=${array[@]:1} export ${array[0]}="$val" # Dump them into a string for the log file DUMPARG="$DUMPARG $ARG\n" done
    • JaredBuschJ

      pull substring from string in bash

      Watching Ignoring Scheduled Pinned Locked Moved Solved IT Discussion bash scripting asterisk
      4
      0 Votes
      4 Posts
      565 Views
      JaredBuschJ

      said script

      [jbusch@pbx ~]$ cat unpause_all.sh #!/bin/sh set -e rasterisk -x "queue show ${1}" | grep paused | grep -o Local.*/n | while read -r member do rasterisk -x "queue unpause member ${member} queue ${1}" done
    • Emad RE

      nohup

      Watching Ignoring Scheduled Pinned Locked Moved IT Discussion nohup linux shell bash
      6
      2 Votes
      6 Posts
      1k Views
      black3dynamiteB

      This is what I do when I use nohup.
      I usually create a file with the current pid just in case I need to stop it.

      nohup wget 'https://example.com/fedora.iso' > wget_fedora.log 2>&1 & echo $! > wget_fedora_pid.txt kill -9 `cat wget_fedora_pid.txt` rm wget_fedora_pid.txt
    • wirestyle22W

      Locating a script that you don't know the name of in Linux

      Watching Ignoring Scheduled Pinned Locked Moved IT Discussion bash linux
      59
      2 Votes
      59 Posts
      3k Views
      Emad RE

      @wirestyle22

      usually they are stored in /usr/local/bin

      that is why you can run them anywhere

    • scottalanmillerS

      Tracking Down Ubuntu BASH Session Closing

      Watching Ignoring Scheduled Pinned Locked Moved IT Discussion ssh linux openssh ubuntu ubuntu 16.04 ubuntu 18.04 bash shell zsh
      45
      1 Votes
      45 Posts
      5k Views
      matteo nunziatiM

      @scottalanmiller said in Tracking Down Ubuntu BASH Session Closing:

      @matteo-nunziati said in Tracking Down Ubuntu BASH Session Closing:

      @scottalanmiller said in Tracking Down Ubuntu BASH Session Closing:

      If I use zsh, I'm good. If I enter BASH from zsh, I get kicked out after several seconds. Definitely is something to do with BASH.

      Stupid tryout: use bash and then enter zsh before being kicked out. Still out?
      To understand if it is the firing of bash itself or the stay in bash...

      No, the underlying bash remains until the ZSH closes. Same as if you were running top from it, for example.

      So basically bash is able to run long running jobs with your user...
      It's the interactivity with the shell to be broken... Meh.

      Sorry the thread is long, did you mention any test from zsh with:

      Bash <-- ok this kills the session
      Bash -i any difference???
      Bash -l ???
      bash --norc
      bash --noprofile

      From bashman page

    • scottalanmillerS

      Shell Speeds, Bash and PowerShell

      Watching Ignoring Scheduled Pinned Locked Moved IT Discussion bash shell powershell
      91
      0 Votes
      91 Posts
      9k Views
      RojoLocoR

      ^^^ It's always hilarious when a scumbag scammer thinks their input is valuable.

    • JaredBuschJ

      Make this command better

      Watching Ignoring Scheduled Pinned Locked Moved IT Discussion scripting bash sed rsync directory comparison
      5
      1 Votes
      5 Posts
      731 Views
      M

      @JaredBusch : I'm not certain if this fits the bill, but what about the "diff" command? Of course, this does nothing to sync the files but does offer a way to simply compare the directories.

      diff -rs manxam jaredbusch

      This will get you :

      Files /home/manxam/TEST and /home/jaredbusch/TEST are identical Only in /home/manxam: i_am_manxam Only in /home/jaredbusch: you_are_jared
    • DustinB3403D

      OSX Shell Error Operation Not Permitted

      Watching Ignoring Scheduled Pinned Locked Moved IT Discussion apple osx quarantine shell bash scripting security troubleshooting brew
      2
      2 Votes
      2 Posts
      729 Views
      DustinB3403D

      Just used this again today, as another script I have had this attribute.

      Not sure when the attribute was written to the script though. But it's working now.

      This is the full error.

      /bin/sh: bad interpreter: Operation not permitted
    • PenguinWranglerP

      Text file manipulation into CSV

      Watching Ignoring Scheduled Pinned Locked Moved IT Discussion powershell bash
      21
      0 Votes
      21 Posts
      2k Views
      1

      @penguinwrangler
      Good work! I admit I would have been to lazy to go through all that. I would just have written a program to deal with it straight up instead instead of trying to use nix commands and scripting. Anything to avoid "escape hell" as I like to call it.

    • scottalanmillerS

      NextCloud Automated Installation

      Watching Ignoring Scheduled Pinned Locked Moved IT Discussion linux fedora installer nextcloud script bash selinux storage cloud storage
      76
      6 Votes
      76 Posts
      13k Views
      W

      Is there anything new with updating the script? 🙂

    • 1
    • 2
    • 3
    • 1 / 3