Questions tagged [bash-scripting]

Bash scripting is making scripts in the Bash shell language.

Filter by
Sorted by
Tagged with
-2 votes
0 answers
17 views

Recursively Query Audio Quality

looking for some guidance (aka someone to do it for me) for a script to delve into my "music" folder and then list out all the songs' reported bitrate/depth. I'm well out of practice but I'm ...
user avatar
  • 75
0 votes
0 answers
8 views

transforming ASCII text to camel_case + .-: should I use tr, sed/awk, or perl to be most POSIX?

I've got a variety of ASCII text, in single lines. I would like to: tr '[:upper:]' '[:lower:]' (change to lower-case) tr -s ' ' (squeeze multiple spaces into one) keep existing '_' and '.' characters ...
user avatar
0 votes
0 answers
12 views

Tabby: very frequent broken pipe error

I am using Tabby on Ubuntu 16.04 I am getting very frequent broken pipe error, and that too for simple commands like ls kill -9 5827 What is wrong? and what could be done to fix it
user avatar
  • 566
0 votes
0 answers
29 views

User Group Creation @ SSH key script issue

Based on my requirement of dev sever ,I have Created a Linux function that will create dev user, but code I have tried find some issues , My requirement are like this: 1.Take the users's first name ...
user avatar
1 vote
2 answers
45 views

Unable to get sudo to work in script when using cron

Environment: RHEL7.9 Access: No root access. I have sudo access to some commands (no password) Issue: my personal crontab calls a script with sudo, sudo isn't working. I have a script.sh that calls ...
user avatar
  • 188
1 vote
0 answers
33 views

Unexpected behaviour in bash function

I'm scratching my head why a bash script won't work. I've condensed it to the following: #! /bin/bash function syncuser() { cat ~nagios/.ssh/authorized_keys cat /home/$1/.ssh/...
user avatar
  • 63.9k
0 votes
1 answer
61 views

Making a bash script execute ssh

I want a bash script to start multiple SSH connections to multiple linux servers in multiple new bash windows, not for further processing, just to connect with a simple command instead of having to ...
user avatar
0 votes
0 answers
16 views

Pull dmidecode info over SSH and save info to local file with hostname entry

Scripting is not my strong suite, but I'm trying to learn. Trying to pull dmidecode info, specifically 'Product' from the dmidecode output, on remote systems from the main server, and save the info ...
user avatar
  • 1
-2 votes
1 answer
36 views

Symlink that runs a script when accessed (Linux)

I would like to make a symbolic link that refers to a file and runs a script every time it is accessed (specifically one that shows a notification and logs to a file). After a quick search of Google ...
user avatar
0 votes
1 answer
34 views

how to call bash function on login as root user

I'm using Arch (with Xfce) and need to run a bash function when I log in to my OS. The function that I wrote, needs to be run by root access. This is the function: my_func() { sudo -v sudo chown ...
user avatar
  • 101
0 votes
1 answer
53 views

How can I modify this bash script so that the port argument is optional?

I often connect through ssh to Docker containers running on a remote server. Every time the container is stopped or removed, I need to copy my ssh key on the container again, in order to connect. For ...
user avatar
  • 317
1 vote
1 answer
72 views

In Bash: "source" a (dynamically) created script, without use of a temporary file

Example, for your amusement: $ f=/etc/os-release; . $f; cat $f | sed -re 's/(.*)=.*/printf "%20s: %s\\n" "\\$\1" "$\1"/' printf "%20s: %s\n" "\$NAME" &...
user avatar
  • 7,660
1 vote
1 answer
45 views

Echo variable which references another variable in shell script

Statement: "$k"_Id_avg="$(grep -i "$k"_Id_avg file.txt)" and $k is a loop variable. Now I want to print the value stored in the above variable, how can I do it? I have ...
user avatar
0 votes
1 answer
32 views

Why !(%) in xargs doesn't work correctly?

I'm attempting to use the following code to omit the last file while copying the rest into a destination folder: ls -Art | tail -n 1 | xargs -I% cp !(%) ~/test_dst/folder1 The first two pipes get the ...
user avatar
  • 375
0 votes
1 answer
26 views

Finding primers on fasta files with position, line and column information

I've some fasta files which contain exactly 80 columns per line. Forget about the definition line that starts > and consider the rest that has around 1250000 lines. I needed to find some primers ...
user avatar
  • 375
0 votes
0 answers
14 views

How to run a kubectl exec of a string expression?

I am trying to generalize a specialized script dumping a kubernetes pod's JVM stats. There are multiple known commands I can run, but they are all predefined. As this is a poweruser script, I want to ...
user avatar
  • 101
0 votes
0 answers
56 views

Automating Build of FFMPEG on Ubuntu 20.04 with NVidia acceleration support

I'm trying to automate deployments of a server with a nvidia gpu for video transcoding and need to build ffmpeg from source with nvcc support. I've gotten the bash script working up to the point where ...
user avatar
0 votes
1 answer
79 views

Executing Remote Script With Remote Console Output

I can ssh to a RPi 4 from Windows 10 and start a remote Python script, but the output of the script appears on the Windows console. Tried using nohup to be able to close the Windows console without ...
user avatar
  • 13
0 votes
0 answers
25 views

How to update Server configuration file in the IBM WebSphere Application Server (int app svr V 8.5)

Update Server configuration file "server.xml" in the IBM WebSphere Application Server (int app svr V 8.5) I am able to setup/run Java Spring Boot Web Application (the war file) on the IBMi ...
user avatar
1 vote
0 answers
62 views

Unable to run Bash Script in Cronjob on Mac

Below script can execute from normal user but I can't able to run script through cronjob on macos(bigsur): Following error comes when script is executing through job security: ...
user avatar
0 votes
2 answers
90 views

Download and then run a file with a script

I am trying to download 2 files and then run them both. I would like to do this in a script but I am not quite sure how to best accomplish that. right now I am doing it manually in terminal: wget http:...
user avatar
  • 1
-2 votes
1 answer
42 views

error validating url from youtube in bash

I have a following code: read -p ":" URL regex='^(https?\:\/\/)?(www\.youtube\.com)\/.+$' if [[ "$URL" =~ $regex ]]; then echo "not valid url " exit ...
user avatar
  • 101
2 votes
1 answer
371 views

How to detect in Bash when Curl fails downloading non-existent file?

I'm using curl to download a zip file. curl is called from a bash script: curl --user joedoe http://1.2.3.4/files/joedoe.zip -o /tmp/downloaded.zip I'd like to detect when the target zip file does ...
user avatar
  • 645
0 votes
0 answers
36 views

what is wrong with the spaces in this string?

i have following string (a version number): 2.2.0 (15). but the problem is, I can't trim the whitespaces. are there some curious whitespaces in bash? because if I do this: local test=" ${var} ...
user avatar
  • 125
-2 votes
1 answer
56 views

List/Print oldest and newest file in each directory

Could use a bit of help guys. I need to produce a report for the oldest and newest files that are residing in each unix directory The structure is simple Main folder with multiple subfolders that ...
user avatar
0 votes
0 answers
55 views

Bash check array membership with regex

I have just started bash scripting as of this morning, so forgive me for my less-than-adequate skills. I have a GitHub action where I scp files which have changed on a push event to the production ...
user avatar
1 vote
1 answer
23 views

Move files to new folderif string matches

I'm trying to go through a number of folders and check their contents. If one or more of the files inside matches any of the strings in a given list, I would like to move those files to a new folder. ...
user avatar
  • 11
0 votes
1 answer
50 views

Extract all emails from a text document

I have a document that contains text and HTML tags, and there is are a lot of tags like <label>abc@gmail.com</label> How do I extract all the emails from this document using Linux commands....
user avatar
  • 1
0 votes
0 answers
30 views

How to impelement a script for automatic router internet switch if one router network down

My requirement show in above image. I want python or shell script for automatic router internet switch if one router internet down. My concept is based on router redundancy. I am using Ubuntu 14.04 OS ...
user avatar
0 votes
0 answers
33 views

Variables inside commands inside if statement

I do not understand why this does not work: existing_user=$(ldapsearch -x -b "cn=group,ou=group2,dc=company,dc=com" -H ldap://127.0.0.1 -D "cn=admin,dc=company,dc=com" -w "...
user avatar
0 votes
1 answer
114 views

Modify user in openLdap via bash script

Can you please help me put this command into if statement (bash scripting): $ ldapmodify -D -h password: [enter password] dn: cn=vipb,ou=groups,dc=example,dc=com changetype: modify add: memberUid ...
user avatar
1 vote
1 answer
144 views

passing bash variables to expect script or scripting expect from inside bash

This script is intended to mount the contents of my server at home as a read/writeable drive in mac os. Unfortunately due to the fact that my house has a dynamic public ip address, the ip address of ...
user avatar
1 vote
2 answers
42 views

Creating multiple symlinks from a string

I have the following script: #!/bin/bash test="../t1,../t2,../t3" ln -sf "{${test}}" . Above this directory consists of 3 directories: ../ ├── script │   └── test.sh ├── t1 ├── ...
user avatar
  • 13
1 vote
1 answer
29 views

bash search and replace replaces extra character

I am trying to use bash' Parameter Expansion to replace a dollar-sign and am having trouble. I've tried variations but nothing I've tried works, what am I doing wrong? Example: in_amt="($12.34)&...
user avatar
0 votes
1 answer
49 views

Killall -9 chrome, but not chrome-beta

Both Google Chrome and Google Chrome Beta are named "chrome" in the process list. I want to kill all instances of chrome, but keep all instances of chrome beta;) Any pointers as to what ...
user avatar
0 votes
1 answer
141 views

removing old BTRFS snapshots with bash

I'm trying to build my own little backup script, I want to use BTRFS snapshots and keep them for a while. Meanwhile, creating the snapshots is no longer a problem for me, but now I would like to ...
user avatar
0 votes
1 answer
96 views

how to insert a phrase after a word with sed in mac

I have the following code: sed -i "/#alias/a alias ll='ls -laGh'" /etc/zshrc sed -i "/#alias/a alias l='ls -l'" /etc/zshrc in the file /etc/zshrc I have: #alias but when ...
user avatar
  • 101
0 votes
0 answers
102 views

Bash script treating a multiple arguments like a single argument. Need multiple arguments as multiple arguments

Like "sudo" I would like to create a command that lets me test if the web page can do things like ping, wget, cat, etc. This bash script works OK for single commands like 'www ./test.py' but ...
user avatar
0 votes
1 answer
55 views

How to bulk delete zip files without extention in linux

I have a folder full of different files but without extension. How can I delete all files that are zip files?
user avatar
  • 3
0 votes
1 answer
29 views

match a string with a whitespace in bash

I have the following string with the following path: #!/bin/bash FICHERO_MARCADOR="/Users/javier/Library/Application\ Support/Google/Chrome/Default/Bookmarks" cp -p $FICHERO_MARCADOR ./...
user avatar
  • 101
0 votes
1 answer
40 views

Trouble with a bash script running as a systemd service restarting another systemd service the first time

I've written a bash loop and named it freud.sh. freud.sh #!/bin/bash set -x while : do sleep 30 systemctl stop pacemaker sleep 30 systemctl start pacemaker done Here is my unit file: [Unit] ...
user avatar
2 votes
1 answer
239 views

How to download a portion of a YouTube video

I often come across YouTube videos that I need to crop parts from, but these videos can be long and downloading the entire video just to process a small part of them would take too long and be very ...
user avatar
  • 10.3k
0 votes
1 answer
44 views

Using `-to` instead of `-t` when using YouTube link as input

This answer shows how to get a portion of a YouTube video by using URLs as input. The command works mostly fine, but I want to avoid using -t as I need to cut between specific timestamps and I'd ...
user avatar
  • 10.3k
0 votes
2 answers
121 views

Using read to capture multiple variables from a command's output

I have a youtube-dl command that when run outputs two new lines, and I'm trying to capture each of those to variables. Here is what I have so far, but for some reason I can't understand, it only ...
user avatar
  • 10.3k
0 votes
2 answers
31 views

if statement - simple bash scripting

I am working on a simple script that checks if there is .vimrc file and what is configured in that file: if [ "$(ls -a /root | grep .vimrc)" = ".vimrc" ]; then echo "...
user avatar
0 votes
1 answer
37 views

Bash script special character

I am learning bash scripting, and I found this command in the book: case `date +%a` in Can someone explain what does + and a mean? I found that the % sign is there to check our output from the left to ...
user avatar
0 votes
2 answers
71 views

How to check in bash if a function's arguments does not contain any parameters

"Argument" vs. "Paramter" First of all, let me clarify what I mean by: if a function's arguments does not contain any parameters Given the following ls command: $ ls -a ...
user avatar
  • 256
0 votes
0 answers
60 views

find the main disk of a montpoint

So I need help with this, I want to find every multipathed disk or LUN /main resides on i.e sd[a,b,c,d] then put the results in a file. sda 8:0 0 893.3G 0 disk ├─sda1 ...
user avatar
0 votes
1 answer
62 views

Cause of lagging process execution

I am running two programs. One python program which generates a set of large files and writes them to an external hard drive I have mounted to the computer. The second is a bash script which cleans ...
user avatar
  • 109
0 votes
0 answers
25 views

In bash, why does the if [ -n ] test return true for an empty string? [duplicate]

This might sound a like a silly question to most people, but it is my first day learning shell scripting, so. #! /bin/bash str="" if [ -n $str ] then echo "True" else echo ...
user avatar
  • 541

1
2 3 4 5
18