Questions tagged [shell-script]

Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

Filter by
Sorted by
Tagged with
0
votes
0answers
24 views

Loops not working in bash when bash script is run with sudo on Ubuntu [duplicate]

I have a very basic script that uses a loop to count to 20: test.sh: for i in {1..20} do echo $i sleep 1 done When I run "./test.sh" on Mac and Ubuntu, it counts to 20 as expected. when I ...
0
votes
0answers
58 views

Killing a process running executed with sudo without using sudo in kill command

So I have a server, and I have access to sudo to do one thing only: run a single whitelisted script (I'll call it the target script). I do not have access to sudo anything else. Problem is, this ...
1
vote
0answers
39 views

How to determine if an EXIT trap is defined for a BASH subshell?

Below is a example BASH script. #!/bin/bash exithdl() { echo "in exithdl subshell=$BASH_SUBSHELL" >&2 } trap exithdl EXIT fun() { echo "in fun subshell=$BASH_SUBSHELL" >&2 ...
2
votes
1answer
37 views

Pass arguments to script

I have shell script that pass arguments to script, like this: script.sh argA argB arg1 arg2 arg3 argN ArgA and ArgB consider for name and family. Arg1 ... argN are phone numbers. (Maybe 1 to N ...
0
votes
1answer
24 views

'expect' not matching server response string

I'm using a bash script to log into a telnet server and execute a number of commands. It looks like: login_and_run.sh #!/bin/bash unset TELNET_USER_NAME_STRING unset TELNET_PASSWORD_STRING unset ...
2
votes
0answers
44 views

Change $(basename “$0”) Output From Executed base64 Encode

Inside script.sh echo $(basename "$0") Then I Encoded script.sh using base64: echo '#!/usr/bin/env bash' > other.sh echo "echo '$(base64 script.sh)' | base64 -d | sh" >> other.sh ...
-2
votes
1answer
98 views

Is there a reason to use \+ or \- in date arguments?

I use date \+%F\-%T to show date and time in this format: 2019-08-15-21:34:58. From man date: %F full date; same as %Y-%m-%d %T time; same as %H:%M:%S I recognized no explanation for \+ or \...
0
votes
1answer
40 views

“No such file or directory” when trying tto run script in background from another script

My run.sh script errors out when I try to run another script in the background.. Console Error String ./run.sh 30: nohup bash /export/home/myself/bin/mytestprogram &>/...
0
votes
0answers
29 views

Debian - how to start script after boot

I am building deployment system on debian v9.40 (PXE). I will build a script which will read basics parameters, save them and initialize flashing procedure. Unfortunatelly during this process I need ...
1
vote
3answers
99 views

How to assign select statement from Oracle to shell variable

I have a script which is working fine in TOAD: SELECT max (ID)+1 from apps_details; When I'm trying to run it in the shell script, I'm getting an error: DB_CONNECT="XXXXX/XXXXX@XXXXXX" echo "...
0
votes
2answers
75 views

How insecure is it passing a password to curl via cat

I have a script which executes curl many times. I'd like to enter my password only once (so I don't want curl to ask for it on every execution). I don't want the password to appear in process list or ...
1
vote
0answers
55 views

Bash: kill process and all subprocesses without using group id

TL;DR, I need a way to kill a process and all descendant processes, without killing siblings with the same group id, without output printed in the terminal, and with a non-zero exit code. I have a ...
-1
votes
2answers
44 views

Passing txt file as an argument to a script while running

I have a script as below for File in $(cat $IMPORT_PATH/*.txt); do echo `date +'%m-%d-%Y %H:%M:%S'` "starting $File execute" > $Import_Success_Log ./cli.sh -a execute -i ...
1
vote
3answers
45 views

Counting the number of columns below a value for each row

I need to count the number of columns that have a value < 5 by row. My data looks like this: 1.2 8.9 4.5 2.8 4.9 10.1 15.3 1.1 2.1 4.3 3.9 3.3 . . So the desired output is like this: 3 2 ...
0
votes
0answers
32 views

script runs under my user but fails under root and cron

Using some google and questions, I made this bash script if [[ $(curl --socks5 localhost:9050 --socks5-hostname localhost:9050 -s https://check.torproject.org/ | cat | grep -m 1 Congratulations | ...
0
votes
0answers
21 views

Automate gpgtar encryption bash script

hHello :) I am trying to automate a script (that runs from within Nautilus scripts folder) that encrypts folders locally: #!/bin/bash chars=abcd1234ABCD for i in {1..8} ; do echo -n "${chars:...
0
votes
1answer
24 views

inheritance of a variable from source overriding my current variable

index.sh file: #!/bin/sh source "global.sh" echo "${CODE_DIR}/SOMETHING" global.sh file: #!/bin/sh APP_DIR="/app001/Documents/files/" CODE_DIR="${APP_DIR}/code" When I run index.sh: Expected ...
-1
votes
2answers
69 views

Bash variable execution

I try to learn bash as i can. In this example, when i use my script without argument : restart_alfresco.sh Connection to slql-fresc-bdd1 closed. Usage: /root/bin/restart_alfresco.sh status|start|...
1
vote
2answers
53 views

Awk: match a block of code inside a enum block in a header file

I am trying to parse C++ headers to delete any #ifdef inside a enum. i needed this because a headerParser module I am using has this bug of skipping any enum with #ifdef in it. I have a shell script ...
1
vote
1answer
19 views

Remove all .html files - if else statement won't work [closed]

This is my first bash script. I need to remove all .html files from the current folder. I have this: #!/bin/bash HTML_FILE_COUNT=$(find . -maxdepth 1 -type f -name "*.html" | wc -l) echo "Remove $...
-2
votes
1answer
46 views

Write a recursive script to move all files one folder up [closed]

I know that there are multiple questions already asked of this type. Still, some of them still remain unanswered while, the others don't answer my query. Consider the following directory hierarchy: ...
1
vote
1answer
47 views

Piped command hangs on killed sleeping child

I use a 'watchdog' function to perform a failsafe wakeup if a certain command hangs. This is implemented by running a background task that sleeps for 30s and then executes the wakeup. If the parent ...
1
vote
1answer
41 views

how to get number of total core include thread

as all know lscpu give the info about number of CORE and number of Thread lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): ...
1
vote
1answer
36 views

How to run local bash script through multiple ssh

I have a local bash script that I would like to run on the second ssh server. Here are the steps: user$ - local machine user$ ssh -A ssh - logging into the first ssh user@ssh01:~$ ssh server2 - ...
-2
votes
2answers
27 views

How to tar all newly generated files in a directory every two hour and moving that tared files to another directory

files will generate every 5th minute in /kit directory.Want to tar all the files and move that files to /kit/bkp directory every 2 hr
0
votes
1answer
31 views

Bash Script Time each function and Time total Script Execution Duration

I've written a bash script and would like to implement a timer that will also get the total time of the scripts execution duration and also the time that each loop iteration takes. For example, in the ...
9
votes
1answer
881 views

Trying to write a shell script that keeps testing a server remotely, but it keeps falling in else statement when I logout

Trying here to write a shell script that keeps testing my server and email me when it becomes down. The problem is that when I logout from ssh connection, despite running it with & at the end of ...
-1
votes
1answer
57 views

trap command not found [closed]

I run into this weird behavior of trap. According to trap's manpage: When a subshell is entered, traps that are not being ignored are set to the default actions. This does not imply that the trap ...
1
vote
1answer
49 views

Is there a way to output the contents of the currently running script?

I'm trying to use a command in my script that will print the literal text contents of the script itself. I tried using cat $(pwd)/$(basename "$0"), but doesn't work. Anyone figured out how?
2
votes
0answers
28 views

Auto trigger history search in terminal using fzf (fuzzy finder)

Is it possible to trigger fzf history search automatically in zsh shell? In this video, the user clicks "Ctrl+r" to start the history search and then starts typing. Is it possible to start the ...
1
vote
1answer
38 views

Why does shopt -s nullglob remove a string with question mark in an array element?

This little setting drove me crazy: shopt -s nullglob I use it in my bash 4.3 script as a global setting to avoid errors scanning empty directories. Now I found a strange problem which I do not ...
0
votes
0answers
69 views

how to grouping timestamp and value with awk

i have some complicated log and need grouping by minutes and value. below some sample log : 2019-08-09T19:01:53:594+07:00 - info: {"tag":"request /browse","tagName":{"status":"05","message":"...
1
vote
0answers
39 views

Computing pair-wise time differences in mili seconds between matching records in a data table

I have a three-column table of data of the following form: TIME MPID CPID 14:00:04.909 10048 370007 14:00:05.320 10048 370007 14:00:05.462 10048 370008 14:00:05.761 10048 370008 14:00:...
1
vote
0answers
37 views

Piping Backups through Compression and Encryption

I am trying to backup a disk image of a local system to a remote system, in a way I can automate by bash script at a later point. Backing up and restoring was going well until I introduced encryption, ...
2
votes
2answers
86 views

How to test if a file check in remote server with ssh and if statement

I'm trying to test if a file in $SSHPATH/$ID.* exists. I'm using sshpass to supply a password so I don't have to type. I want to execute a code if file doesn't exist if [ "sshpass -p $SSHPASS ssh ...
1
vote
0answers
19 views

How to get auto complete to work on aliases [duplicate]

I have created some aliases but tab completion doesn't work for them. I mean I created an alias impulse typing impul+TAB gives expected result but after that it doesn't works. I mean it doesn't ...
0
votes
3answers
36 views

Convert rows into a single extended column

Hi I would like to take a row1 of data and put it into a column, then do the same with row2 and extend the column. Ex: This 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...
-2
votes
2answers
34 views

Find files in nested directories using REGEX [closed]

So I have a folder with this structure. topperlayer ├── layerone │   └── testfile └── layertwo Like layerone and layertwo, there can be many directories, even subdirs under the layers. ...
4
votes
3answers
138 views

Running a command on first column using system() function on awk

I have the following code which I'm running to extract some ip addresses and count the unique of them. For example ./my_program | awk '/^10./{a[$1 FS $2]++ } END { for(i in a) print i,a[i]}' > ...
1
vote
1answer
46 views

sed - include all found in between 2 pattern, except what's found between other pattern

I have a sed pattern search as below: sed -n '/<centerline/,/<\/centerline/p' This finds everything in between <centerline> and </centerline> I want to ignore all the cases where ...
0
votes
1answer
19 views

How to get server name inline with top output?

I've been given the task to use top(htop is not an option on our system) to monitor CPU usage over time. If a user is on a server and using over 100% for longer than an hour, an email alert will be ...
0
votes
2answers
37 views

My script doesn't run according to cron schedule

I have made (with a Stack Exchange help) a script that checks if the web application is available and restarts the web app daemon in order to get it running again (usually helps until I'm at work). It'...
0
votes
4answers
58 views

shell scripting to fetch the file contents

a log file get generated every minute in directory called "data_logs" log file name : abc.log.2019041607 abc.log.2019041608.. contents of the log file like this R_MT|D:1234|ID:413|S:1 R_MT|D:...
1
vote
5answers
56 views

How to restructure a date variable in bash

I have a bash script that takes user-inputed dates in this format: dd.mm.yyyy and saves it as a variable $date Now I need to modify this variable to be in this format: yyyymmdd for further use. So ...
0
votes
0answers
30 views

Unrar and extract to source directory name

I am extracting multiple files from multiple sub-directories using the command: unrar x -r -o- /SOURCE/*.rar /DESTINATION/unrar/ Now x should extract with full path, but everything gets extracted ...
1
vote
2answers
46 views

Using nested while loops for ffmpeg processing

I'm trying to use ffmpeg's signature function to perform a duplicate analysis on several thousand video files that are listed in the text file vids.list. I need to have it so that every file is ...
1
vote
11answers
89 views

Adding missing zeroes in the begining of each line where is less than 4 signs

I would ask you how solve this problem: I need to put 0 every line where word have less than 4 signs. Example input file: 30 1 508 A0EA A0EB A0EC A0ED Desired output should be: 0030 0001 0508 ...
-1
votes
4answers
77 views

Check if all lines in a file are same

If the following file contains same content in all line it should print "contents are same". $ cat file example-line example-line example-line If any of the line differs from others, then it ...
1
vote
2answers
38 views

Dialog/Application before login/desktop-manager comes up

After a preseed installation of ubuntu (or any linux dist) I want to display a message/warning for the user that some installation or configuration is happening during the first boot. Unfortunately ...
2
votes
2answers
136 views

Search and replace a substring only if another substring is not present

I have the following strings in a very large document: 1.test.html# 2.test.md# 3.http://test.html# 4.https://test.md# 5.http://test.md# 6.test2.md# Now I want to replace every .md# with .html# but ...