@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.
@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.
@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.
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:
And for fun lol....
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
@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
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
@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
@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
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
@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.
@stacksofplates said in A script to pull updates from GH or use History:
@DustinB3403 said in A script to pull updates from GH or use History:
So to clarify here, the goal is to allow admins an easy way to pull the most current update script. Not to run it for them on a set schedule.
(reason being is if we auto-force an update, and that update breaks their system, I don't want to have that on my mind)
I don't understand the hangup here. The cron job I pasted above does not update anything. It doesn't run any scripts. It doesn't force anything. Where this is coming from I have no idea.
This is from sidebar conversations regarding the topic. It has nothing to do with the cron job you posted.
I guess I could do a wildcard at the beginning and end of whatever I'm searching for with killall but that freaks me out a little. I could accidentally do a lot of damage with that.
@mlnews said:
And this is the current site for the project...
https://github.com/Pash-Project/Pash
I love it when people port garbage to other platforms