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

learn more… | top users | synonyms (2)

0
votes
0answers
54 views

Extract text above exception line in output [closed]

I have the following error output from a program: 2016-06-20 02:09:28,264 Mbr10063a cOqZeJiM BaseAction.java:getAlerts:618 ERROR [AlertAction] Could not open JDBC Connection for transaction; 2016-06-...
0
votes
0answers
25 views

Shell syntax var=${var:-$var2/file} [duplicate]

I came across the following syntax while working with some shell scripts. I am unable to understand what it does and I am not sure what should I search to get right documentation for this var=${var:-$...
24
votes
1answer
2k views

If “bash <file>” works, why is “source <file>” throwing an error?

I have the following script: #!/bin/bash set -x if :; then echo a fi If I run bash /tmp/file, a is echoed, but if I run source /tmp/file, I get: bash: /tmp/test: line 6: syntax error: ...
1
vote
3answers
71 views

Extract filename from another filename

I receive notification files for different files. I want to extract the filename from these notification files which I would use in another process. The first 4 strings of the notification file will ...
0
votes
0answers
47 views

A script to remove and put menu on Xfce

I encountered a bug in Xfce that if I move an program icon on panel, the applications menu disappears. I found the solution that if I remove the menu and then put it back, the menu won't disappear ...
0
votes
1answer
74 views

Simple if command not working in csh script

I have made a basic shell script using IF command as a purpose to help myself as I am a beginner. Problem is that when I execute this script using source overspeed (after giving myself execute ...
1
vote
2answers
132 views

Remove leading whitespace before possible shebang

I have a large collection of non-binary files in one place. Some of them have shebangs and of those some have (for some inexplicably reasons) whitespaces in front of the shebangs. This includes empty ...
0
votes
1answer
152 views

Check if date is n years old

I have a variable $date with format yyyy-mm-dd and I would like to check if it is exactly 1 year, 2 years (and so on) old. That's what I tried so far: dates=$(echo $date | cut -c6-10) todays=$(date +...
0
votes
0answers
33 views

How to transfer a big file simultaneously to several machines remotely? [duplicate]

I have launched 10 instances on a cloud service, and these are the steps that I want to do in parallel (simultaneously): 1) Copy a big input text file to each machine 2) Run a java program called ...
2
votes
1answer
131 views

How do I get bash to give a relevant error for a file with windows line-endings?

Suppose I have the following shell script: #!/bin/bash \n echo "Hello World" \n Running it gives Hello world. Now suppose I have the following shell script #!/bin/bash \r\n echo "Hello world" \...
2
votes
1answer
170 views

Print recursively all directories and subdirectories

I am trying to print all directories and sub directories with a recursive function but I get only the first directory. Any help? counter(){ list=`ls $1` if [ -z "$(ls $1)" ] then ...
-4
votes
0answers
22 views

shell scrit for posting the json file to curl [duplicate]

i have multiple json files which need to be post to curl one after the other. so am using loop in shell scrip which is not working for me here. can some one help me the write code to do so ??? here ...
1
vote
1answer
48 views

Can I check if create_ap works?

I am currently using the script create_ap to emit a Wifi Access Point (WAP) using my Raspberry Pi, which is running Raspbian. How can I check if the AP is up and running using a bash script? For your ...
-1
votes
1answer
46 views

How can I pass the file names to xargs and truncate them? [closed]

I have to write a script which will ssh into servers and truncate log files My script is #!/bin/bash for server in $(cat c10_servers.txt) do ssh $server " ls /var/log/hello grep -i hello.log. |...
1
vote
4answers
74 views

script to delete files if there is no corresponding file with the same name but a different extension in another subdirectory

I have a series of preview images and RAW files in a directory structure (shown below), I quickly review the preview images, and delete those that I don't want. The RAW files are in a RAW ...
3
votes
1answer
34 views

Capture output (sdout/stderr) of SSH port forwarder

I would like to store the error below in a variable: ssh -M -S /invalid/path/forwarder.socket -fnNT -Llocalhost:6301:remote_server:22 proxy_server muxserver_listen bind(): No such file or directory ...
1
vote
1answer
44 views

Make an IF condition out of result we get from remote server

I need to check for files availability in remote server, and based on the files availability i need to make an if condition. I have tried the below commands in a shell script to list the files in the ...
3
votes
3answers
90 views

md5sum check (no file)

So I'm trying to check dozens of files using a shell script. The file check happens at different times. Is there a way to do this? md5sum -c 24f4ce42e0bc39ddf7b7e879a File.name or even better ...
4
votes
4answers
41 views

Generate line number / “index” within a range from a date seed value

I'm trying to create a bash script to display a word of the day (random for each day). I have a dictionary file that on each line has a word and its definition. I'd like to use date to get a unique ...
1
vote
2answers
26 views

How to use top in a shell script to track memory consumption of a process?

I was wondering if there was a way to use top or another program to track the memory consumption of a script I will be running. I was using runtime.totalMemory - runtime.freeMemory But that'...
1
vote
3answers
47 views

Multiple logical operators, ((A || B) && C), and “syntax error near unexpected token”

I'm working with Bash 3, and I'm trying to form a conditional. In C/C++, its dead simple: ((A || B) && C). In Bash, its turning out not so (I think the Git authors must have contributed this ...
3
votes
1answer
47 views

How can I Split a text file into new files

I have a text file in the following format: 001|fileA 002|fileA 003|fileA 004|fileB 005|fileB 006|fileC . . . xxx|fileX I need to split this file into the files corresponding to each "|". The names ...
0
votes
2answers
39 views

Execute command when user interaction is detected ( ex: moving mouse, pressing key )

I am trying to make a bash script to turn down the brightness to lowest when idle for a certain amount of time but reverts back to its previous brightness when it detects user interaction whether it ...
3
votes
3answers
37 views

Proper type casting in bash script for use with while loop and modulus

I am trying to write a script to get a random, even hex number. I have found the the openssl command has a convenient option for creating random hex numbers. Unfortunately, I need it to be even and my ...
1
vote
2answers
46 views

sed: Grabbing and replacing all data between last backslash and a comma

I have data in a csv format that looks like this: F1309-042543,07/14/09 01:39:25,N/A,C:\windows\system32\netsh.exe,N/A,True F1309-042543,11/21/10 03:24:02,N/A,C:\Windows\System32\networkexplorer.dll,...
0
votes
0answers
20 views

Ensure that file socket is already opened

I'd like to open a simple file socket that can run in background like: nc -l -k -m 10 -U my_socket -c cat & so other processes can connect into it with nc -U my_socket -c read. After this ...
0
votes
0answers
23 views

I want to write a UNIX script which reads files in a directory and if they are more than 5 days old, log the names and delete the files [duplicate]

This is the code that I tried: LOG_DIR = /home/xyz/ LOG_FNM = Delete_Logs.log files = "$(find -mtime +5)" for file in "$files"; do - exec rm{} echo "$file deleted !" >> $LOG_DIR/$...
1
vote
2answers
57 views

Creating a text file from other text files

I have a text file like this word_1 root_of_word_A word_2 root_of_word_B word_3 root_of_word_C word_4 root_of_word_A And other document like this root_of_word_A root_of_word_1 root_of_word_B ...
-1
votes
1answer
29 views

How to record numbers of array elements based on selection comparision criteria

I have many files which has many 2x2 arrays. In the present example I show only one file (file1) Input file(file1): 1: 6.1703 541.631 46.0391 2: 6.1930 537.446 45.9239 3: 6.1931 177.171 288.579 ...
0
votes
1answer
35 views

Shell to do action, when someone visited my webpage [closed]

Can someone make a script that beeps or does some action when a user visits my webpage (apache2)?
0
votes
1answer
24 views

Bourne to grep and forward specific text from across a LAN

I'd like to develop a shell that keeps forwarding me the greped text(say compilation errors or warnings, in a single txt output) to some E-mail ID or on some NAS mount point, most importantly from ...
0
votes
2answers
70 views

parsing using loop and assigning row numbers to file

It is a bit complicated. i have a configuration file. it looks something like this. customer="airtel" model_name=fast programmer_typ_of="dev" Now the 1st column contains all the keys and whatever ...
1
vote
2answers
40 views

Appending output of command in for loop

I am using a simple for loop to process certain input files and get the output in one file. What I am using is for k in ../some_directory/*.txt; do command (containing -i $k -o outputfile.txt); ...
0
votes
1answer
37 views

find: missing argument to '-exec'

this is my first post, as I am completely new to the programming world. Basically I'm taking a UNIX class and I have an assignment asking me to check the size of regular files in my home directory for ...
2
votes
1answer
66 views

Getting script's real absolute path in /bin/sh

I'm looking for a way to get the real absolute path to the current /bin/sh script. It should work for situations like this one: /path/to/symlink/in/PATH/somescript -> ../../Package/current/...
0
votes
0answers
36 views

How to resolve a variable's value inside an array in bash

I have a few files whose names I have assigned into variables. (There may be n number of files). Those variables are passed into an array. Now I want to print the names of the original files using ...
0
votes
3answers
83 views

Splitting a text file into new files

I have a text file in the following format: Model 1 Atom…. Atom…. Atom…. ENDMDL Model 2 Atom…. Atom…. Atom…. ENDMDL Model n Atom…. Atom…. Atom…. ENDMDL I need to split ...
0
votes
1answer
32 views

Linux Check Image Exists at Apache URL

I'm writing a program that uses a Linux command to check if a file exists on the local server. The program executes a command with a supplied argument ls *ARG_GOES_HERE* &> /dev/null and ...
-4
votes
1answer
37 views

Back Tick version of this command [closed]

TAROUTPUT=$(tar cvf /tmp/incremental_backup . tar $(find /etc -type f -mtime -1)) Please suggest how can i use backtick for above command
-1
votes
1answer
21 views

Having hard time getting my public key to work

I'm using scp to send from a shared Hostgator site to Adrive's scp server. I created a private and public key with puttygen.exe. First time, I put in my password for the passphrase. Second time, I ...
0
votes
0answers
60 views

Run console printing command after tmux starts up

I'm starting tmux from zsh with the window split into two panels. The only issue I'm having is screenfetch starts up and prints to both windows. Ideally I only want it printing on the left window. I ...
-5
votes
3answers
98 views

How to add all the numbers of a specific column in UNIX without using awk command?

Let us take a sample file with the contents below, an expense report containing items and their prices: $ cat file Item1,200 Item2,500 Item345,900 Item20896,800 Item111,600 Now, a friend challenged ...
3
votes
1answer
36 views

Messages on new terminal after using nohup

I'm trying to run a few commands asynchronously on a login script (.bash_profile). When I open a new terminal, I see messages like this. They also show up when I log onto a system over SSH. Last ...
1
vote
1answer
36 views

Redirect bash variable into netcat

I am attempting to write a bash loop that passes a bash string into netcat. The command that I execute is: nc -nv [ipaddress] [port] << EOF 10000 EOF I am writing a bash loop to perform this ...
1
vote
0answers
11 views

Avoid delays from network calls in logon and logoff scripts

I'm trying to tune some scripts in my test environment. My test environment is specialized and it exists to test software. The software includes Botan, Cryptlib, Crypto++ and OpenSSL. Whenever I log ...
0
votes
2answers
36 views

variable interpolation in shell script

I wrote the following shell script for a pg backup: #!/bin/bash PG_USER=donato DATABASE=mydb SERVER=216.58.219.174 DIR="$HOME/pg_bak" DATE=$(date +"%m_%d_%y") FILE="$DATABASE_$DATE" ERROR_FILE="$...
-2
votes
1answer
55 views

Bash script if - else contitions [closed]

I would like to do create a bash script that downloads a specific installer from the internet, installs it, create a desktop file that launches it, make it auto start, then remove the installer, but ...
1
vote
1answer
36 views

Convert GPS coordinates with bash script

I need to convert to a specific format some gps coordinates which are the output of the exif information of a picture. This is the typical output: exif:GPSLatitude: 10/1, 10/1, 10/1 exif:...
3
votes
1answer
54 views

Parsing a C string literal in shell

I have a valid C string literal that I would like to convert to its actual representation. Sadly the %b conversion specifier for printf does not define escapes for ? ' and ", which are all valid in a ...
-2
votes
2answers
61 views

Find all line in a file which start with g or any digit from 0to9

How do I find all lines in a file which start with g or any digit from 0 to 9? Can any one help me using command line? I try and I know how to do if start with g but don't know how to do with g and 0 ...