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

learn more… | top users | synonyms (2)

-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
47 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
45 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
71 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
25 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
45 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
36 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
55 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
39 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
65 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
35 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
82 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
51 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
35 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
34 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
34 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 ...
-3
votes
3answers
69 views

If, Then, Else Scripting

I have a log file that contains several lines, each with an IP, username, and URL. I need to create something that will take each IP in the line and, if starting with a 10 will append the word "ON" to ...
-3
votes
1answer
54 views

Search a file in unix system

I am trying to find a file using find and locate commands. locate command is faster but it requires to update the slocate db. And find command is slower but it wont require any updates. I am trying ...
2
votes
1answer
48 views

backup file locally in shell script

This is my crontab: crontab -e 30 5 * * * sh /home/donato/Documents/pg_bak.sh Every day at 5:30am I want to execute a shell script I created called pg_bak.sh. This is the contents of the shell ...
1
vote
2answers
70 views

how to edit next line after matching pattern and append the line if doesn't exist

I am looking for changing a file content which is repeated twice with that replacement I want to add extra line to second content in the same file Example file User YOURNAME IdentityFile ~/.ssh/...
1
vote
1answer
42 views

Replacing variable containing \ with sed

i am trying to replace $old string with $new string in file where: old=ESX_10.1.1.1\@11.11.11.11 new=host_15_11_0_111.static I am using sed command: sed i "s/${old}/${new}/g" /filename but it ...
0
votes
1answer
24 views

User Input Shell Script Syntax Error

I'm new to shell scripts and all, and wanted to write a script that would automatically perform this command for me: sudo aireplay-ng -0 (given number) -a (Router MAC Address) -c (Target MAC address) ...
1
vote
1answer
32 views

using a bash script to run an interactive program

this is day one for me for bash. perhaps this question has already been asked, but i've tried google and have come up empty. maybe because i don't know how to articulate my question. i have a ...
2
votes
3answers
67 views

Why is my elif being treated as an else statement in my bash script?

I'm building a bash script that uses wget to GET information from a server using a REST api. I'm using getopts to parse options given to the script and then using an if statement to redirect the ...
3
votes
3answers
90 views

How to do a loop to process two input files

I am using awk to do match two files and then multiply the elements of file2 and file1. awk 'NR == FNR{a[$1]=$2; b[$1]=$3; next} /:/ || !NF{print; next} {print $1, $2*a[$1], $2*b[$1]}' ...
1
vote
2answers
46 views

Read n lines at once in a loop using bash script

I have a file in this format: Start tracing process 17134 17136 17137 17138 (/usr/sbin/nginx)... [...
2
votes
2answers
68 views

How to execute Command which is in a variable

My Condition is like below. Could anyone help please? SEARCH="find `pwd` -name" bash> $SEARCH resources.xml | grep $SEARCH_DIR | grep $1 | grep ‘cells’ But am not getting the pwd as referenced ...