A script is a sequence of commands or instructions that are executed by an interpreter program rather than compiled into a standalone executable program.

learn more… | top users | synonyms (2)

0
votes
1answer
79 views

#! /bin/bash or #! /usr/bin/env bash? [duplicate]

I'm trying to write some provisioning shell scripts for Vagrant dev environment. I'm used to start bash scripts as follows #! /bin/bash But after surfing through some git repos I found out that in ...
0
votes
2answers
41 views

How to loop over each file in a directory, if and only if the directory contains the .csv files?

/dir1/--$ ls 1.txt 2.ssl.txt If the dir1 directory has the given .csv files, then only process the files listed in the .csv in a loop one after another. Here as the dir1 does not have any files ...
0
votes
0answers
42 views

Logging to a file in tabular format

I am trying to print something into a file through the script which will be sent as an attachment to the mail. Now what i am willing is to preserve a proper formatting within the file. Can i print ...
0
votes
4answers
47 views

How to log from inside the script along with stdout

I am aware that I can log using tee But I want to log from inside my script, at the same time display the content on the stdout. Example, my code looks something like this: names=$(print("name1 ...
0
votes
2answers
103 views

Check whether an IP belongs to a specific range

I have a log file that lists whitelisted IP ranges in this manner: "217.29.0.0-217.29.255.255", "204.12.0.0-204.12.255.255", "198.54.223.0-198.54.223.255", I am also working on a bash script which, ...
0
votes
1answer
52 views

CentOS and Stop Shell Script running on screen

I'm trying to automatize my system, sorry but I'm not very experienced on Linux distros, actually using CentOS 7. Every time I restart the machine I need to do: screen -S bun then on that screen I ...
1
vote
0answers
83 views

script can't write to systemd journal

to make it short: I want to write to the systemd journal from a script. printf "%s\n%s\n%s\n" CODE_FILE=/etc/zsh/zprofile CODE_LINE=31 MESSAGE="could not read /etc/dircolors" | logger --journald ...
0
votes
1answer
91 views

Running two commands at the same time?

Here is the nature of my problem: I'm using my raspberry pi to run a wikipedia server, so I'd like to make a launcher (desktop icon) that starts up the wikipedia server and opens the web browser to ...
1
vote
2answers
440 views

Cron Bash Script - echo to current terminal instead of /var/spool/mail/root

Is it possible for a Cron Bash Script to echo to the current session terminal instead of /var/spool/mail/root I have a script which writes errors to a log file but any supplemental/unimportant info I ...
1
vote
1answer
21 views

Interactive bash script

I'm writing a script that shuts down the Apache service, performs a function, and turns it back on. I'd like to get some type of interactive confirmation for each process. I'm not familiar with ...
0
votes
0answers
84 views

How to write a script with Android Debug Bridge command in it

I am trying to write a script to automate some testing, and the fist step is connect to my device and update the /lib/modules/ directory with the recent version of a device driver on my host. That is ...
2
votes
1answer
38 views

Launch a command when connected to a host

In a dormitory I live in the access to Internet is somehow clumsy. The procedure follows Connect to the network (via WiFi/Ethernet) Login by ssh sshpass -p password ssh login@domain.edu.pl ...
1
vote
2answers
148 views

What type of file is /dev/core or /proc/kcore?

While scanning a filesystem for changes with a shellscript, I forgot to exclude /dev, so core got tested too. Strangely enough, which ever way I test it, it is not consistent for a type: $ if [ -f ...
0
votes
0answers
79 views

permission needed for Python to access USB drive?

I got this Python script that reads media files from USB stick. It used to run fine, today it keeps giving me OS Error: [Errno 13] Permission denied: media/myName/usbName when the script runs the ...
4
votes
1answer
62 views

How to find how many windows are opened in GNU screen?

I am trying to automate my work flow. I have a script that opens individual window in screen for each IP in a list. Imagine setupscreen.sh <IP1> <IP2> .... After all windows are open, each ...
0
votes
1answer
59 views

Compare first column of 2 files based on the second column using the delimiter ;

I need to compare below 2 files. The head_file: 2345;int builder( 1000;char type::edit::display <test>( 250;void unamed_string_tree* The ref_file: 2000;int builder( ...
0
votes
1answer
39 views

How can I replace a filename with .ear in a file-list using sed?

I have a file whose contents look like: /appl/as/var/spool/ears/mps/ear1.ear ... I want to replace the name of only ear1.ear with ear2.ear and I am using the below sed command, but with no luck: ...
0
votes
2answers
48 views

Grep for string but ignore commented out items with string

I'm looking for the words gmail or outlook in a directory. Although there are some lines commented out with the word gmail and outlook in it. How can I grep for this? I tried a bunch of things but I ...
0
votes
0answers
26 views

Preserve formatting of the attachment sent by the script

I have written a script which at the end of execution send a mail with an attachment. Through my script i am making two files , one serves as email body and the second as an attachment. I noticed ...
0
votes
0answers
47 views

How to parse the output of running bash script?

I'm writing a simple bash script for downloading files via aria2c. I would like to parse the progress display so I can display it in the form I want. Currently the output looks like this: *** ...
3
votes
4answers
215 views

Bash script condition always passing even when grep should return nothing

I am having issues when trying to return the one image file that fits the parameters. $1 is the search parameter, in this incident it is "real" which is a tag on one of the images (not two) in the ...
1
vote
2answers
61 views

`last` alternative showing logins only for current user

I'm aware that I can use last $USER, however this won't work correctly or securely on machines with many users - no user should know another users IP or when they logged in. Is there a known solution ...
2
votes
3answers
498 views

how to implement logrotate in shell script

test.sh #!/bin/bash echo "Hello World" test2.sh #!/bin/bash while true do sh test.sh >> /script_logs/test.log & done I want to implement logrotate to control the log file size, so ...
2
votes
1answer
147 views

Rsync backup script for multiple servers

I have simple script that backing up data from remote server via ssh using rsync. I have external config file for that. In this config file I have variables: OPTIONS, REMOTE_IP, SOURCE and ...
0
votes
1answer
44 views

Bash script - sshing into one computer and then immediately into that comupter's network's modem

I am currently attempting to automagically reboot my modem that for some reason or another will only allow certain types of small Linux OS's to ssh into it - and not the one I am using. So, rebooting ...
2
votes
1answer
85 views

Background vs foreground task and running tasks in parallel

Since I'm new to Linux, apologies if I'm not using the correct terminology. I'm trying to run a number of tasks in parallel (using the background shell operator). However, I need to first run two ...
4
votes
3answers
63 views

Script that outputs the total number of lines in all the text files that are passed as arguments

So I'm working on a script that will accept arguments that are text files, and should output the total number of lines in those files.  For example, if I say ./myScript file1 file2 file3 it will ...
0
votes
1answer
60 views

How to get a position of a specific image within another image?

I have many PNG screenshots with an identical piece of graphic in each of them. The piece has the same dimensions in all of the images. What command line program can I use to find the position of it ...
1
vote
1answer
56 views

AIX Non GNU tool for text replacement

Contents of the file : PS1="$(hostname):${LOGNAME}:\${PWD} ${PROMPT} " PS1="${FGOLD}$(hostname):${LOGNAME}:\${PWD} ${PROMPT} ${NORMAL}" PS1=abd PS1="$(hostname):$LOGNAME:\$PWD $PROMPT " export PS1 ...
0
votes
1answer
88 views

ARRAY- Accept user input and output the corresponding choice from array

I'm working on a script that has an array of around 10 elements. All I have to do is that the script will accept user input of minimum 0 elements and maximum 10 elements (of the array) and it will ...
0
votes
1answer
47 views

Using RS-232 output as keystrokes

I'm a bit desperate now. I've been trying to do a simple thing (under windows it IS very simple) as reading RS-232 data and sending it as keystrokes. I tried softwedge - which is supposed to do ...
3
votes
3answers
420 views

How to rename multiple files to their contents' MD5 sum?

I would like to rename some files to their contents' MD5 sum; for example, if file foo is empty, it should be renamed to d41d8cd98f00b204e9800998ecf8427e. Does it have to be script or can I use ...
4
votes
4answers
557 views

Delete several lines from a file using grep

I have a file with multiple lines which looks like that : brand,model,inches,price dell xps 13 9000 macbook pro 13 13000 asus zenbook 13 10500 I want to ...
2
votes
1answer
44 views

Merge content of one file into another file by replace a function

I am working on a shell script which is getting data from another program and I am using that variable value to read the content from file keep appending to different files after some modification to ...
-1
votes
1answer
89 views

How to get last quarter in Bash Script

I have a script that gets the proper quarter but I need to get the (quarter - 1) quarter=$(($(($((10#$(date -d $year$month$day +%m))) - 1)) / 3 + 1)) Currently this returns 3, I need it to return ...
0
votes
0answers
74 views

How can I run multiple php file in a single shell file?

I have a .sh file from which I want to run multiple .php file. Here is my code: #!/bin/sh while true; do hr=`date +%k:%m` if test $hr -ge 00:00 -a $hr -lt 00:05 then ./test1.php ./test2.php fi ...
0
votes
2answers
84 views

motd - UNIX - AIX - different welcome screens for diff users

is it possible to segregate different motd files for different users ? So Admin gets a different message and others diff one....
3
votes
1answer
217 views

What does eval X=\$$i mean in UNIX?

I have a small script with the following lines echo mom,dad |awk -F, '{print $1,$2}' | while read VAR1 VAR2 do for i in VAR1 VAR2 do eval X=\$$i echo $X done done OUTPUT: mom dad ...
0
votes
4answers
71 views

Getting different parts of a line

Suppose I have a line of text as follows: I have a nice car Is there any way to get different words of the line at different positions individually (say, I want to get 'have' and 'nice' parts) ...
-1
votes
2answers
47 views

comparing a line with its following lines inside a file

Supposing I have a file named sample.txt which contains data in the following format: 1 John 2 Crema 3 Abraham 1 John I can read the file line by line using the following way: while read p do echo ...
3
votes
1answer
230 views

How to make a sudo passwordless script for any user in bash

I want to be able to run a sudo command inside of a bash script but I was wondering what if I want any user in my server to be able to execute the script without to provide them with my root password, ...
0
votes
1answer
55 views

combining output of grep command [duplicate]

Suppose I have used the grep command : grep 'pattern' 'filename' and have got the result : John Brown Is there any way to concatenate the outputs into a single one like: John Brown And also ...
2
votes
1answer
76 views

Is it possible to start a command from bash and send a keystroke to it

I'm trying to start Firefox from bash and I want it to open the webconsole on start (this can be done by pressing F12 rigth after it started). Is there a bash command that starts the programm and ...
1
vote
3answers
24 views

how to edit a bilingual text by scripting?

I have a column of words in which English words are glued to Chinese words like this: abominate******** abhor************* (The stars represent the Chinese alphabet) I want to write a ...
3
votes
1answer
34 views

How can I find my client's linux box on the internet automatically?

I'm looking for a way to have a client's machine "phone home" periodically so that I can easily do a ssh login if necessary. I was thinking a simple script that grabs the public IP address and posts ...
1
vote
1answer
104 views

How to kill inactive user logins on Solaris?

On a Solaris 10 server if i do a w, I get this: 12:26pm up 85 day(s), 1:13, 6 users, load average: 0.38, 0.36, 0.38 User tty login@ idle JCPU PCPU what blah pts/1 ...
3
votes
1answer
39 views

functions arguments

I am having trouble with what should be a simple bash script. I have a bash script that works perfectly: function convert_to () x_max=2038 y_max=1146 x_marg=100 y_marg=30 x_grid=150 y_grid=150 if ...
3
votes
5answers
836 views

Bash: Parse multi-line into single-line commands

I have to write a Bash script which checks if another Bash script contains a certain command line. Since Bash allows you to split a command line over multiple lines, my script must be able to merge ...
4
votes
4answers
337 views

Run the same script on several servers through SSH

I regularly need to update some Ubuntu 12.04 (Precise Pangolin) servers (Rackspace). What I do now is: Copy a file to a server using SCP Log on to the server using SSH Stop Tomcat Do some ...
0
votes
1answer
40 views

How to find maximum number of different strings?

I have a file: 2.0-00-04 2.0-00-03 2.0-00-02 2.0-00-01 2.0-00-00 1.0-00-02 1.0-00-01 1.0-00-00 How can I find maximum number of each group? In the string above, output should be: 2.0-00-04 ...