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

learn more… | top users | synonyms (2)

0
votes
2answers
60 views

Bash script arguments not being passed to function? [closed]

I'm trying to pass the arguments when invoking a bash script to a function defined in that script. In my head this is trivial but in practice seems more difficult. Script is: #!/bin/bash function ...
1
vote
4answers
47 views

Linux replace last character in a csv file to new string

I am new to shell scripting. I created a script that extracts data from a database and loads it to a csv file. I am using SunOS hstz1454 5.10 system. Data looks like this below: 124,Y,Y,Y,Y,S ...
4
votes
2answers
97 views

How to tail a log file by time?

Say my log file(log.txt) is something like 2014-01-01 22:30:30 something happened.... 2014-01-01 22:30:31 something happened.... 2014-01-01 22:30:41 something happened.... I want to tail this file ...
0
votes
0answers
20 views

Multiple here documents in a bash script to drop in and out of sudo is causing error “Sessions still open, not unmounting”

I'm attempting to write a setup script that I can run on multiple machines to run a bunch of installers (requires sudo) but also do things like pull down a git repo (I want to run that as the normal ...
0
votes
0answers
19 views

st terminal run block of code

I can run a command with a new terminal by typing st -e <command> How can I run a block of code this way, for instance: for i in {1..100}; do echo $i sleep 1 done I thought it would work ...
2
votes
6answers
276 views

How to Remove last comma of each line on csv using linux

I need to remove the last comma of each line. I have only one csv file, which looks like this: 98,N,N,N,N,S, 99,N,N,N,N,S, 101,Y,Y,Y,Y,S, I have the following script, but it is not working: for ...
1
vote
2answers
41 views

change colour of `echo` for particular line in shell script in Linux?

i want to change colour of echo particular statement in Linux shell script example : echo "invalid entries" echo "valid entries" echo "valid entry" i want red color for echo "invalid ...
0
votes
1answer
21 views

Trying to request a variable before running a curl and read back as integer

echo -e "Enter layoutID: \c" read layoutID echo -e "Enter playlistID: \c" read playlistID echo -e "Enter siteID: \c" read siteID curl -H "Content-Type: application/json" -d ...
2
votes
2answers
62 views

is a script, program being run under current shell or child shell?

I am confused with regards to the following - if i execute a script or run a program in the current shell by typing on its name 1st) it search in the $PATH variable, to find the location of the ...
0
votes
2answers
49 views

Grepping from a parameter file for non matching text

I am new to shell scripting. I have a paramameter file and I'm trying to grip a word and then remove only that word leaving everyting elese. For instance: An Example would be: #Parameter File ...
-1
votes
2answers
65 views

Executing script after error

I want to continue execution of shell script even after error in particular step, but it is getting terminated after error if [ condition ];then cmd else cmd1 return 4 fi cmd2 I ...
-5
votes
0answers
23 views

Need a XML Shell Script

I need a shell script that can print data from a start node and an end node when i search with a string within that node, without printing the other duplicate node, if any.
2
votes
1answer
90 views

arithmetic syntax error in string compare

I have written a shell script which takes file name as parameter e.g user/test.txt. I want to make this file parameter optional if user does not wish to provide file name he/she can give as "None" ...
2
votes
3answers
122 views

How to sum column values for each row in two csv files using bash script?

I have two CSV files and i have the requirement to calculate the sum of the 8th column from File1 and File2 for every row. The two CSV files have exactly 24 rows each and to simplify the things i have ...
-2
votes
0answers
54 views

Transform CSV file using shell script

I am having various CSV files in a particular loaction, files: CPU_USED_20150729.csv, CPU_USED_20150730.csv, etc Data inside the file is like: CPU_Used CPU_Used CPU_Used CPU_Used CPU_Used ...
1
vote
1answer
68 views

Shell Script does not send email from Cron job [duplicate]

I have a shell script which sends email when the disk is more than 80% full; when I run the script as sh -x script.sh or ./script.sh I get an email but when I keep the script in cronjob I do not get ...
0
votes
1answer
19 views

Have to transform some bunch of csv in req format and store it in some other location with same name

I am having some input CSV files INPUT_FILE: A_B_C_NFM001_20150729.csv A_B_C_NFM002_20150729.csv A_B_C_NFM003_20150730.csv I want output file also with the same name as input after performing below ...
1
vote
0answers
31 views

How to normalize irregular data values

From a PHP table I get the values graphically represented. However some of the data recieved is 'damaged' or incorrect thus yielding a non-sensible graphical representation. The hours (y-axis) is ...
3
votes
2answers
36 views

Cycle between open windows with wmctrl

I have a script that I'm trying to use to make handing applications easier. Right now it gets the window id of an application name (the first parameter) and checks if the window_id exists or not. If ...
2
votes
1answer
45 views

make sure all lines in a textfiles don't have the same value

I have a text file that contain multiple lines. Some of the lines have contain same value. What I want is to make sure that all of the lines do not have duplicates or "triplicates". Sample: ...
2
votes
1answer
41 views

Running compilation scripts only if the source file is more recent than the compiled programe

all. I'm not sure if this question belongs here or some other site but I figured I would start here and some helpful moderator would kick me over if there is a better location. What I am trying to ...
1
vote
1answer
45 views

How do I get a folder name using a wildcard and check for it's uniqueness

I want to move a series of file into different folder based on their ID, but I want to make sure that the folder I'm moving the file to exists and is unique The folders have a matching ID as the ...
0
votes
1answer
68 views

mv: cannot access file

Good day All, I have a script with permissions - 770 root:root script.sh. The scripts has to zip then moves files with permissions - 644 rex:roger file.csv. With a bash one line - mv file.csv ...
2
votes
3answers
140 views

Shell script executed with cron results in different size file than executed manually

I have a RHEL server that I am running a MySQL database on. I have a Bash script that executes mysqldump that creates a backup file. The backup file created when executing the script directly in ...
2
votes
3answers
182 views

!(*.sh) works on the command line but not in a script

When I use the code below in a terminal on Ubuntu, it works fine: rm !(*.sh) -rf But if I place the same line code in a shell script (clean.sh) and run shell script from terminal, it throws error ...
2
votes
3answers
122 views

Shell script to fetch part of file name from input file and transform it into output file

Source_FIle: /path/to file/A_B_C_D_201507290915.csv Destination_File should be like : /some/other/path/to file/A_B_C_D_201507290915.csv I need to transform Source_FIle and storing with the same ...
0
votes
2answers
37 views

How to run to parallel gnome-terminal windows?

I'm looking to run two independent parallel gnome-terminal windows with some parameters, from 1 shell script. So far I've got this: #!/bin/sh gnome-terminal -e window1.sh & gnome-terminal -e ...
0
votes
2answers
35 views

wget, logging the output and the response

I calling an url using wget. This url gives me a response, its a Message id. I want to write the logs to a log file, with the message id as well. Also the log should be appended each time. I trying to ...
0
votes
0answers
10 views

Audio File Search, Count and Sort - OS X or Synology

There is a collection of audio files on a Synology NAS. Approximately 24,000 albums worth, that I need to analyse and report on. I will need to: Count total number of files Count types of files ...
0
votes
1answer
42 views

How to call variable in KSH shell script

#!/bin/sh # This script if for checking the status of SSHD2 Number of connections CHKOUT="Please also Check the Number of ORPHAN / DEFUNCT Process on `hostname` :" DFOUT=`/usr/bin/ps -eaf | grep ...
4
votes
1answer
57 views

“$@” expansion for user defined variables

I'm trying to get a (bourne shell) variable to expand like "$@" so it produces multiple words with some having preserved spaces. I've tried defining the variable in many different ways but still can't ...
0
votes
3answers
46 views

How do I create a directory for every file in a parent directory

I have parent folder and inside this folder I have 4 files ParentFolder File1.txt File2.txt File3.txt File4.txt I wanted to create subfolders inside the parent folder and ...
0
votes
1answer
64 views

Disable ctrl c and ctrl z while a script is running

I have a script that takes about 45 seconds to run. How can I disable Ctrl-c and Ctrl-z while a script is running?
1
vote
3answers
48 views

Why won't my FTP script get all the files using mget command?

I am having a script which pulls data from different servers whose details it reads from external file. It reads the files and the verbose output shows all the matching files but it fetches only one ...
0
votes
3answers
50 views

prevent repeated emails via bash to overquote user

I need some help to improve the idea/implementation.Scenario is local mini ISP. users accounts are stored in freeradius/mysql. The task is to send user email who have consumed 80% of there assigned ...
2
votes
1answer
20 views

Manipulating RGB values in PNG from command line

I'm looking for a command line tool/script which allows you to balance the colors in a PNG - similar to the "Adjust Color Balance" effect in Gimp (Colors > Color Balance...). Something like this ...
4
votes
2answers
123 views

Run an app with a window manager behind in a separate X server

I want to launch an app in a separate X server. It needs a window manager behind it, though. I created a script #!/bin/sh x-window-manager & my-gui-app and launched it with xinit ...
0
votes
2answers
61 views

How to use cp command in bash script to copy files with spaces ans $ characters in it? [duplicate]

I am trying to copy some files with spaces and $, @ symbols in their file names in a bash script but the script fails to copy the files stating it cannot find the file. I can see that it is treating ...
3
votes
2answers
135 views

Using bash variables in perl command in bash script

I am trying to generate a hashed password as in /etc/shadow file, using bash script. The user is prompted for the password which is saved in a variable PSWD. I have extracted the Hash and the salt ...
1
vote
5answers
364 views

Check number of words in a file that contain a specific letter

Bash command to check number of words in a file that contain letter “a”
1
vote
1answer
46 views

error ./c.sh: line 24: [: too many arguments in shell program

I am trying to make a shell script to print the amount of time user was logged into the system but I encountered a too many arguments error. I tried many methods from the internet but none worked. ...
3
votes
6answers
144 views

How to run no more than n parallel subshells

I am trying to run subscripts from a main script, but I want to make sure than no more than n subscripts run at the same time. The following simplified example illustrates. Each subscript creates a ...
2
votes
1answer
88 views

Issue with ':' character in Bash script over SSH

I am currently writing a script that will perform backups on a set of databases, comress them, encrypt them, transfer them to a separate storage machine, and verify that the file made it successfully. ...
2
votes
3answers
182 views

Remove the ^L (aka \f/FF/form-feed/page-break) character

How do I remove the ^L character and the blank lines that come after it on a unix file? I have tried the below and have been able to remove the VT and spaces but am failing to remove the ^L character ...
1
vote
1answer
57 views

How to use SFTP in a script to non-interactively pull file from remote host?

I want to use a shell script to pull a file from another server. I have written a script where i can do this but i want the script to work non-interactively so that it doesn't prompt me for the ...
1
vote
1answer
67 views

Reload network interfaces without rebooting

I'm doing a BASH script for Arch Linux in a Raspberry Pi 2. The thing is that in some point I'd like to reload the network interfaces without reboot and have my new named network interfaces (en0 and ...
1
vote
2answers
50 views

Best way to make variables local in a source'd bash script?

I have a bash script that generates a report on the progress of some long-running jobs on the machine. Basically, this parent script loops through a list of child scripts (calling them all with ...
1
vote
4answers
71 views

How to number a string in each line of a file

Given file.txt that looks like this: line_ some text line_ some text line_ some text How can I number the lines like this with Bash: line_1 some text line_2 some text line_3 some text Here is my ...
1
vote
2answers
25 views

How to pass an argument from a bash script to 'x-terminal-emulator -e bash -c'?

Let's say I've got this script : x-terminal-emulator -e bash -c 'echo hello > ~/text' I call it foo.sh and make it executable. If I execute this script I'll have a text file in my home folder ...
1
vote
2answers
72 views

What's the most efficient way to log crontab shell script errors with error occurred time?

A common way to log crontab task errors looks like below: 1 */8 * * * sh /pseudo_path/test.sh 2>> my_err_log It's a concise command, but it can't record the error occurred time, and the path ...