Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [shell-script]

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

0
votes
1answer
22 views

Get data form CSV to move a file

I have a CSV file whit two columns and this information Column1 | Column2 USA | Chicago USA | Dalas FR | France AUS | Sydney AUS | Perth And i have to move all the files whit ...
0
votes
0answers
21 views

Bash script executes command twice with incorrect arguments [duplicate]

I have a script that executes a couple of commands to sort a CSV file according to a certain column. I'm using a function sort() { head -n 1 ${1} > t_${1} && tail -n +6 $1 | sort -t';' -...
11
votes
2answers
398 views

Parameterize chained calls to a utility program in Bash

I have a black box UNIX program used in a Bash shell that reads columns of data from stdin, processes them (applying a smoothing effect) then outputs to stdout. I use it by UNIX pipes, like ...
-1
votes
1answer
64 views

Copy whole directory from source to destination using immediate parent folder as reference in both location

** Problem 1: ** Pre-requiste: Both source and destionion should have the same directory name. Directory's depth level may vary both not the name Notes on source and destination structure: ...
11
votes
4answers
52k views

How to write a shell script that gets executed on login?

I am trying to write bash shell script in Ubuntu 11.10 Linux distro, that will get executed automatically on logging into the system. But I am not able to figure out that what to write in script that ...
0
votes
2answers
53 views

How do i arranged and fill the missing fields from reading two files in bash

I have two text files cat A.txt 10,1,1,"ABC" 10,1,2,"S1" 10,1,2,"ABC" 10,1,3,"baba" 10,2,1,"S2" 10,2,1,"asd" 10,2,2,"S3" 10,2,2,"dkkd" 10,2,3,"ABC" cat B.txt 10,1,1,"ABC1" 10,1,2,"S1" 10,1,2,"ABC"...
1
vote
1answer
25 views

How to remotely find and copy files without permission errors or having to log in multiple times?

The issue I have is that our server has a bunch of files in nested directories that I'm trying to find and copy to a folder on my home directory. This means I can't simply glob all the files like this:...
0
votes
2answers
222 views

Open file from history in Zathura

Is this possible using a built-in command? AFAIK, it is not, so I am trying to define a mapping that uses the exec Zathura command to achieve this. In bash, cat ~/.local/share/zathura/history | grep ...
1
vote
1answer
10 views

How do I wrap a timezone adjustment to the date command in a string?

I'm trying to output the date and time, in a different time zone, in a bash shell script. Following this question, I did this: #!/usr/bin/env bash IL=":Asia/Jerusalem" date "+%a %b %d %R" echo "...
-1
votes
1answer
28 views

Filter command output

I downloaded a program and want to filter the output. This is for a school project. I need a shell script that can do it. The output is from a python program, and I need a script to "fix" the output. ...
0
votes
3answers
41 views

Viewing only the first screen's worth of output on the shell

I am using a bash command that outputs a large quantity of data and all I need is to see the command that was run and the output that fits on the screen afterward. Is there a keyboard shortcut for ...
0
votes
1answer
21 views

AIX restricted shell add entry to inittab

Need a help in adding an entry to the AIX inittab on VIO server. The VIO server is a restricted shell, to add entry to the inittab we need to access the root shell using command: oem_setup_env. I'm ...
102
votes
7answers
366k views

Using the not equal operator for string comparison

I tried to check if the PHONE_TYPE variable contains one of three valid values. if [ "$PHONE_TYPE" != "NORTEL" ] || [ "$PHONE_TYPE" != "NEC" ] || [ "$PHONE_TYPE" != "CISCO" ] then echo "Phone ...
0
votes
1answer
1k views

Starting Resque worker with script doesnt work, starting by hand does

I am trying to figure out why my process doesn't work if started via a script, but works fine if started by hand. Here's the details: script is a resque worker start script. The script location is /...
0
votes
1answer
1k views

linux/shell command to control screen brightness in android

I am working on a kiosk project using an android tablet.If there is no input power to the kiosk for a long time then, the tablet will eventually shutdown.In order to auto-reboot the tab when the power ...
3
votes
0answers
55 views

When coding for Unix/Linux is it convention to use a trailing slash on path names, or to omit it? [duplicate]

When programming for Unix/Linux, is it best practice to use a trailing slash, or to omit it? For example: Trailing slash baseDir="/path/to/dir/" #code# outPath=${baseDir}addition/to/path/ No ...
2
votes
2answers
46 views

How to print all the matched string using awk?

My inputs are something like: ["https://www.tesing.com/watch/80239279"], ["https://www.testing.com/watch/80240715?source=35"], ["https://www.testing.com/watch/80242619?trackId=254015180&tctx=0%...
0
votes
0answers
16 views

“bad decrypt” error while decrypting with openssl

I have created 2 scripts to encrypt and decrypt a password inside a file. The encryption script is as follow: set -x PFILE=/home/user/crypt/pfile echo "changing PASSWORD" P=`echo 'rawpassword' | ...
-4
votes
0answers
33 views
0
votes
0answers
29 views

Creating data delimited by ASCII code 1

Any suggestion how to create a file where the values are separated by ASCII code 1,with data extracted from a table? The format is : columnname1(binary1)columnvalue(binary1)columnname2(binary1)...
2
votes
3answers
65 views

How to capture stderr of function that modifies current environment?

The module function of the Environment Modules1 package does its work by modifying various environment variables of the current shell process. Unfortunately, this function returns 0 whether it ...
4
votes
1answer
1k views

Why does the history command do nothing in a script file?

If I create a file containing #!/bin/bash history and run it, I get no output. Running it manually in a terminal or sourceing the script file does produce output. Why does history not work from ...
1
vote
1answer
1k views

Output print statement in python does not goes into cron log

my crontab looks like this: @reboot sh /home/pi/LCDinterface/shutdownlauncher.sh 2>&1 | tee -a /home/cronlog Content of shutdownlauncher.sh : cd / cd home/pi/LCDinterface date python ...
0
votes
0answers
19 views

Bash String Concat issues [duplicate]

What seems to be going on here with the single quotes that are getting added to my concat'ed string? Something caused by the expansion of close($i)? for i in ${pid_fd_arr=[@]} do ...
0
votes
1answer
33 views

Confusion about how a systemd service is restarted

I am still confused about systemd services being active vs the process still running vs not running etc. Let's say I have the following basic shell script called my_script.sh : #!/bin/sh touch /...
6
votes
3answers
189 views

Redirecting output only on a successful command call

I want to redirect the output of a command (diff in this case) to a file but only if there is a difference in files I'm comparing. For example, imagine I have three files a, b, and c where a and b are ...
0
votes
0answers
15 views

Get thread id by thread name

When I type ps -A -T I can see all threads, and threads name. Is there any way how to get thread id by thread name? When I want to get process name by process name I can use echo $(pidof XXX) , with ...
1
vote
0answers
47 views

How to use the stdin as a file

I have a command that wants a file as input, but I get the input from the stdin and I don't want to create a temporary file. I would like to do the following: #!/bin/bash osadecompile /dev/stdin <...
3
votes
2answers
6k views

Getting a pid for an ssh process that backgrounded itself

So I wanted to call two background ssh processes: ssh -D localhost:8087 -fN aws-gateway-vpc1 ssh -D localhost:8088 -fN aws-gateway-vpc2 These gateways don't have the benefit of letting me set an ...
3
votes
1answer
883 views

Upload to youtube using shell script

I've searched the youtube API but still not clear whether this is possible. I have a shell script that uses FFMPEG to convert a video. After being converted I want to have the video automatically ...
1
vote
1answer
66 views

Reading filesystem type at boot into BASH variable

I have a /etc/rc.d/S11 link to a /etc/init.d file that is trying to set a bash variable of the file system type of a given blkid entry. root@OpenWrt:/# blkid /dev/mmcblk1p3 /dev/mmcblk1p3: UUID="...
16
votes
4answers
17k views

How can I use a variable as a case condition?

I am trying to use a variable consisting of different strings separated with a | as a case statement test. For example: string="\"foo\"|\"bar\"" read choice case $choice in $string) echo "...
3
votes
1answer
64 views

Kill the child process in a child xterm but not xterm

I'm new to Linux. I have python scripts in different files, each one performing a desired function. foo1.py foo2.py foo3.py Each one of these scripts should do cleanup before being terminated. ...
3
votes
1answer
195 views

What is the use of declare with option -t

If you call the command help declare. You will see the following information: -t NAME : to make NAMEs have the `trace' attribute Is there any example that demonstrates the use of this option. I ...
0
votes
1answer
23 views

Usage of variable in {..} [duplicate]

Can someone explain why the following code for i in {1..5};do echo "hello" done prints hello hello hello hello hello but the following num=5 for i in {1..$num};do echo "hello" done prints ...
1
vote
2answers
135 views

Remove duplicates in a file [closed]

I have the following file.txt Plummet Cherist the day -- The Transatlatins <-----------duplicate Mysteriosa <-----------duplicate -- Angel City;Lara McAllen ...
0
votes
1answer
83 views

Bash script exercise in Windows environment

I have this exercise Write a script which creates files File.txt numer.txt the first contains the list of script arguments, separated by newline, the second contains your UID, ...
-5
votes
3answers
51 views

A script that checks deleted files in a number of seconds, given as an argument

Write a script which takes a number of seconds as an argument and then holds the session for the period (sleep), after that presents the list of files that were deleted from your home directory. Use `...
-2
votes
2answers
44 views

How can I Print output lines of this script uniqely and for every line print how many times is it repeated [closed]

#!/bin/bash who |grep "10\.1\.109" | grep -v berianho | cut -f1 -d " " | sort -n| while read user do grep -a ^$user: /etc/passwd | cut -f5 -d: done
0
votes
1answer
19 views

Copying variable value form shell script to constant file

I have appcenter-pre-build.sh in which I am executing another script depend on environment type. If environment is UAT then it will execute uat-pre-build.sh. Here is appcenter-pre-build.sh if [ ...
0
votes
1answer
38 views

How to replace matching words defined in one file on another file?

I have file1 and file2 as shown below, file1 (org8:0.00000001,org9:0.00000068,((org28:0.00137458,(org30:0.00146077,org4:0.00127170):0.00066024):0.00262422,(org14:0.00384582,(((org29:0.00000521,org7:...
1
vote
2answers
1k views

expect script for getting output for multiple servers

I am trying to get output of IQN from multiple servers. I am getting the below error. Error output spawn /usr/bin/ssh VM2 | /usr/bin/cat /etc/iscsi/initiatorname.iscsi root@VM2's password: bash: -c: ...
2
votes
2answers
25 views

toggle a program using bash script

I am trying to make a script that will toggle redshift (a night mode application). So, I've done this, #!/bin/bash pgrep redshift > /dev/null && \ killall redshift || \ ...
1
vote
1answer
35 views

getopts in function that is called more than once in a script, getopts doesn't detect any opts after 1st function call [duplicate]

I have read the getopts man page and am still not sure about this use case. getopts is not detecting any available options the second time a function is called in the same script. As you can see ...
0
votes
3answers
38 views

What is the best way to direct stdout & stderr to multiple logfiles?

I have a purge process that I am running and the command I'm using is : find $sentPurgerFolder -mtime +7 -print -delete >> $sentPurgeLogFile 2>&1 This code is in a while loop that is ...
1
vote
1answer
65 views

$! not being set to the PID of a > >(…) process substitution used with an external command

Bash 4.4.19(1)-release I have below a simple script which is the basis for a logging app. For various reasons I had to use process substitution. The runner is the heart of the app and since ...
0
votes
0answers
20 views

How to append the output variables of a shell script to excel file

I have a script that runs daily at 11 PM and produces variables $endofday_A which will have value "20:03:06" $endofday_B which will have value "20:06:07" $endofday_C which will have value "20:05:25" ....
0
votes
1answer
1k views

Init Scripts: Do I Need a PID File?

I am new to the the world of init scripts and still a BASH neophyte. I'm currently in a situation where I could use some guidance. We run an application that utilizes JBOSS and I need to be able to ...
0
votes
1answer
56 views

Process Substitution ECHOS undesirable 'shell prompt'. Can I disable it?

NOTE: This question has arisen due to asynchronous processing of 'Process Substitution'. The script responses were deceptive, causing many lost hours. A previously related post is here: cat in process ...
-1
votes
1answer
28 views

simple systemd service for execution of shell script

Im trying to start a simple .sh file and it says Failed at step EXEC spawning /etc/start.sh: No such file or directory Content of the gnome.service [Unit] Description=Description for sample script ...