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
54 views

Script to Log Shutdowns and Reboots

I am trying to create a script that will run daily as a cronjob and log all shutdowns and reboots. I've come up with this, but the grep seems to be ignored, and the script results in the output of ...
1
vote
1answer
42 views

How to move directories based on the output of rhash (CRC32 check of .sfv) with bash/perl?

My idea, is to move the CRC-check OK folders (albums) into a lets say "complete+CRC_OK" folder with a script once per day in cron. I would need to put the rhash command in a loop with number of ...
2
votes
2answers
51 views

How to transform string with character codes into quoted form

I have a string like New\x20Folder. Special characters is represented by their codes. I'd like to transform the string into quoted form: "New Folder". The only available tools are bash and bunch of ...
2
votes
1answer
56 views

Updating config files within the script that references them?

I have no problem adding config files to a given script, but automatically updating them is another matter. In this instance I'm providing a few variables to a script, and I'd like the script to be ...
2
votes
2answers
94 views

vim: using a for-loop-iterator-variable in a search pattern

I am trying to use a for loop iterator variable in a vim search pattern to determine for a range of words how man times they occur in a file. What I do so far is: for i in range(1,40) | %s/SiTg//gn | ...
14
votes
4answers
1k views

How to retrieve IP addresses of possible ssh attackers?

I've just cat /var/log/auth.log log and see, that there are many | grep "Failed password for" records. However, there are two possible record types - for valid / invalid user. It complicates my ...
0
votes
2answers
49 views

Why is the suid bit having no effect on a shell or perl script? [duplicate]

As an experiment in playing with the suid bit, I tried writing a script to run apt-get update from a bash script, and then set the suid bit on it, so I could just run ~/update or something. apt-get ...
2
votes
1answer
195 views

Transform .csv into 3 columns and a row

Sample Input: id,Product1,Product2,Product3,Product4 1,0.1,0.3,0.8,0.7 2,0.6,0.7,0.5,0.9 I need output as : id,productname,product_val 1,Product1,0.1 1,Product2,0.3 1,Product3,0.8 1,Product4,0.7 ...
1
vote
2answers
27 views

Substituting file extensions on a variable

I'd like to do the following : create a .tex and directly show it after compilation with evince, ideally it would be like this: showpdf file.tex so I wrote #!/bin/sh pdflatex $1 && ...
3
votes
3answers
608 views

how to execute a bash command in a python script

How can I launch a bash command with multiple args (for example "sudo apt update") from a python script?
1
vote
2answers
93 views

How to copy only files in a specified directory to another folder

I'm trying to copy only the files from one directory (not including folders or any files in its subfolders) to another location using cp /media/d/folder1/* /home/userA/folder2/. It is copying the ...
3
votes
3answers
1k views

Switch user in a shell script without entering the password

I'm running a shell script using terminal from userA. In the middle of this shell script, I switch to userB user using su, but this asks me for the password of userB and I have to manually enter the ...
1
vote
4answers
223 views

bash division of numbers in text file

I have two numbers in test.txt file, I would like a way to divide the second number by the first number and assign the result to a variable or file in a bash script that I can use. I have used awk ...
1
vote
2answers
82 views

Need special validation for shell script

I want to create a bash script which will have lot of options while executing. # script.sh --dry-run --user <parameter1> --pass <parameter2> I heard about getopt option but looks like ...
1
vote
2answers
165 views

Capture errors in a SFTP script

I have a sub sh file which puts receives an input of local directory and path to the remote directory and sends the file to the remote directory. If the remote path is invalid the error cannot be ...
2
votes
1answer
100 views

Please explain the syntax

Can someone explain the syntax of the following commands? II know what they do but was having a hard time getting the syntax, find / -type f -exec grep -H 'text-to-find-here' {} \; cat access.log | ...
-1
votes
1answer
89 views

How to write a auto-completion bash script?

I want to run some functions (which I created in ./.bash_func) in terminal with some files located somewhere. When I type the function and hit Tab Tab I want to list the files located in ./scipts like ...
1
vote
4answers
85 views

Delete all files in a directory

I have a directory which includes some files and some folders containing other files. I'm trying to remove these files in the main directory without touching the folders or their contents. I'm using ...
2
votes
1answer
42 views

Copy files that partially matches another files in another location

I have a list of jpeg files in a directory like this (below is just a sample, like the structure is the same but this there are many fo0# sub-folders, not only fo01 and fo01, where each of these ...
2
votes
1answer
188 views

Remove newlines in file names

I have a PHP code that generates the file name on which wget will append its logs. I generated 2000+ files, but the problem is I am having trouble working with them because I had a mistake of putting ...
-2
votes
2answers
41 views

grep to get all the getters from a java file

I have a java file called Friends.java . There are 5 variables and each variable has its own getter. Assume that all the functions below follow standard java standard, i.e public methodName(){ //Some ...
2
votes
2answers
103 views

Is shell parent of all the processes in linux

I have been trying to understand shell scopes and environment in depth. I have been reading about how if we do export VARIABLE=VALUE it will be available in subshell. So I wanted to ask a question I ...
1
vote
2answers
45 views

How do I update the dates (by 30 days) in the files going to that specific location in unix?

How do I update the dates (by 30 days) in the files going to that specific location in unix? Can awk or sed help ? File format is as below - Thomson: xyz Format: 1 Character_set: ASCII8 File_type: ...
0
votes
1answer
229 views

Linux Bash Script Ideas [closed]

I have been given the task of creating a shell script to show my proficiency in scripting. I am really struggling with ideas on what to do. I would like to create something that is relevant and could ...
0
votes
2answers
130 views

While Read loop to email

I'm having issues with a script i'm writing. I'm trying to monitor free disk space, and to have an email generated for each filesystem over a certain threshold. When using this script with 'echo' ...
0
votes
0answers
25 views

Perform task on waking up from suspend

I have program that misbehaves when my pc wakes up from suspend to ram, it starts using up to 40% of processor time so i usually have to kill it manually. How can i set specific command (pkill in ...
7
votes
2answers
1k views

How to make a temporary file in RAM?

I have a script that will pipe its output to |tee scriptnameYYMMDD.txt. After each cycle of the for loop in which the output is generated, I'll be reversing the file contents with tac ...
0
votes
1answer
25 views

I'm trying to deploy with git to a semi-managed vps, need to write a script to change owners

I'm trying to deploy my sites on my company's semi-managed vps server using this tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps It ...
0
votes
1answer
25 views

How to force decimal addition (#10) when adding numbers with a carry (octal issue)

How can I get 10#1$result to work correctly? When creating a calculator for adding two numbers I am adding together by transversing the digits from small to large. e.g. for adding 51 plus 51 I am ...
-1
votes
1answer
55 views

Command output to file, new lines at beginning

I'm rewriting some 20+ year old Unix scripts and I want the output to go to the screen and a file. I know this is possible with tee. Is there a similar command that stacks new lines on top, at the ...
2
votes
1answer
166 views

use mutt to send email through specific port on CentOS 7

What specific syntax do I use to get mutt to send an email through port 587 on a CentOS 7 server? For example, the sender is me@mydomain.com, the recipient is someone.else@someotherdomain.com, the ...
0
votes
1answer
149 views

Avoid conversion to scientific notation in awk

I have a csv file that contains hundreds of columns. I would like to subtract the value of a specific column from a static number and then print the entire line. The values of that column are long ...
0
votes
5answers
5k views

How to get current working directory? [duplicate]

I want to have a script that takes the current working directory to a variable. The section that needs the directory is like this dir = pwd. It just prints pwd how do I get the current working ...
3
votes
1answer
127 views

how to compare a decimal value with a integer in shell scripting? [duplicate]

Could anyone please help me for comparing a decimal value with a integer in shell scripting? Example: i=1 j=1.2 if [$j -gt $i];then echo "growth" else echo "None of the condition met" fi Im ...
1
vote
1answer
90 views

Batch rename “case duplicates”

I have a folder on my Linux system that is cross-synchronized with other computers, some of them with Windows. The problem is that in that folder there are files that are "case duplicates", i.e. their ...
0
votes
0answers
26 views

Add extra parameter for text label or just echo it outside the call?

I have written a program that allows me to test my functions. I call it like this: do_test function_name expected_result parm1 parm2 For example do_test add_2_nums 10 5 5 Now I need to call the ...
1
vote
1answer
94 views

Shell script runs diffrently based on working directory.

I have a script which runs differently based on current working directory. Basically it processes an .ini file and takes parameters from it and runs mysql backup. Script is running as root user. ...
1
vote
0answers
166 views

Why the output is not written to log from expect script

I am trying to write the output of the netcat command including the command also to a file by logging into remote servers. But it is not writing. What am I missing ? #!/usr/bin/expect -f set user ...
0
votes
2answers
310 views

how to save the contents of a webpage in a file using shell script

how to save the contents of a webpage in a file using shell script. Web page is using URL, username and password to open. curl -O odcview:password ...
2
votes
2answers
92 views

How can I copy and move a sequential subset of files?

I have a directory containing 1772 files named PRC0001, PRC002,... up to PRC1772. How can I copy a subset, for example PRC0257 to PRC1516 to a different directory? I am trying to do this for several ...
2
votes
5answers
1k views

cut for key-value pairs

I am looking for an easy way to cut key-value pairs (where the key is unique and specified) from text, much like how cut can be used to cut a specified column in a CSV file. The keys I'm looking for ...
2
votes
0answers
74 views

programmatically alter kde file associations

Problem: In kde I want to remove a particular file association from every file type Details: I wanted to try out clamTk as a companion to clamAv. It didn't suit my needs so I uninstalled the ...
1
vote
1answer
78 views

Why do some apps leave KeyRelease events to be consumed by next focused app/window

I'm trying to wrap dmenu within some script to feed it input and act on it, however when pressing the Return key to select some dmenu input, a KeyRelease event gets sent to whatever window is focused ...
4
votes
3answers
879 views

Run command automatically when files are copied into a directory

I have two folders called: A and B, in different paths on the same computer. When I add any new file(s) into folder A, I want to copy it to folder B automatically. My folders: /auto/std1/nat1/A ...
0
votes
1answer
533 views

bash if, then and else statement

I am learning bash, I ran into a small problem when trying to write a small script #!/bin/bash clear read num if [ "$num" -eq 2 ] then [ -d "/etc/passwd" ] | sudo cp /etc/passwd /home echo ...
1
vote
1answer
34 views

Possible to deliver centrally configured login scripts on Linux?

In Windows you can assign login scripts to users which run whenever they log into a system which allowing admins to do things like map drives/printers and generally do anything for which there isn't a ...
2
votes
4answers
165 views

Script to delete files that don't match certain filenames

I have a folder with 500,000 images, sorted in subfolders by year and month. I'd like to create a script that does this: If the filename does not match any of the filenames in names.log then delete ...
2
votes
2answers
285 views

Bash menu with multiple parameters in one row

I have searched a couple of days and still didn't found the answer. I hope that you can point me in right direction. I would like to know how to write a bash script with a options, that can be ...
7
votes
7answers
213 views

What is the purpose of having two variables ($@,$*) to transmit the arguments of a command into a script? [duplicate]

I have read of the special variables used in a script $@ and $*. As far as I understand, the arguments used while executing the script are stored into two special variables, once all arguments into $@ ...
4
votes
1answer
123 views

print the content of files

I have a list of parent folders, sub folders and files inside the folders and the sub folders. I used the following command line to list the content of the parent folders and the sub folders: tree ...