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

learn more… | top users | synonyms (2)

3
votes
1answer
51 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
41 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
44 views

Proper type casting in a shell 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
24 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
37 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
28 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
74 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
46 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
40 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
0answers
75 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
40 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
96 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
40 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
41 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
23 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
97 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
110 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
52 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
59 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
13 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
46 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
57 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
45 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
58 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
66 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
75 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
58 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
57 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
81 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
43 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
28 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
40 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
71 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
97 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
53 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
75 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 ...
0
votes
0answers
35 views

How I can directly login to rails console through ssh?

Time to time I repeat the following commands: ssh username@servername cd /projects/rails_project bundle exec rails c production I want to create a shell script, and make alias for this file for run ...
0
votes
0answers
92 views

How to write Shell Script for Mongo Find query.?

i am new to Shell Scripting, Actually i am writing a shell Script for mongo to find specific document, this Shell Script Except a Argument and use in Find Query, So i had write a simple find query: ...
0
votes
1answer
46 views

I accidentally copied part of /* to /some/directory, how should I fix my mistake?

I did something stupid on a remote linux server: my working directory was /some/directory I ran for dir in $(ls | grep "a_pattern"); do mv $d/* ./my_subdirectory; done Now /some/directory/...
1
vote
2answers
77 views

Rename all spaces in image file names inside html php files

Inside different htm.gz, html.gz and php.gz web files I have images and the ones in .jpg format have name with space instead of "-", but in /images/ directory where all images are located they have "-"...
0
votes
1answer
29 views

use of lockfile in script and it significance

I have a code in which below line is used due to which i got stuck.I have hunted the web but did not understand well.just got to know the basic set of info as below lockfile can be used to create one ...
1
vote
2answers
62 views

How to check if some recurring text is missing in a text file?

I have a text file that looks like this: { "mimeType": "web", "body": "adsfdf", "data_source_name": "abc", "format": "web", "url": "http://google.com/", "urls": "...
0
votes
1answer
51 views

What is the most efficient way to check if Node is currently installed?

I am writing a script that will first check if Node is currently installed, if not it will install the latest version of Node. If it is installed, then it will proceed to another function to update it....
1
vote
2answers
33 views

Cronjob runs a script which calls another script

my cronjob look like this: 0 3 * * 0-6 somedir/promotionscript But promotionscript is actually calling another file "config" located in the parent folder of somedir. #promotionscript #!/bin/csh ...
2
votes
1answer
34 views

Sending a text from script to a screen

My whole task sounds like this "Show how many users are working right now, whenever someone has logged out or has logged in, print the new amount of users. Create a new screen and print there text ...
1
vote
1answer
44 views

How to :Autorun scriptshell after user log-in

I am writing a program in java programming language on Raspberry pi. As you know Raspberry pi is working on Rasbian Unix based OS. I have created my java fx gui application and set it to myscript ...