I have written a shell script run.sh to trigger a few tasks based on the user’s input The tasks 1,2 … 6 are php scripts that are run like /usr/bin/php task1.php $TIME with $TIME as an argument for the php script etc… The script runs fine when I type bash run.sh but since tasks 1-6 takes a long time to
Tag: scripting
Skipping a part of a line using sed
I have a file with content like so – @1: 00001109 Each line is of the same format. I want the final output to be @1: 00 00 11 09. I used command in sed to introduce a space every 2 characters – sed ‘s/.{2}/& /g’. But that will give me spaces in the part before the colon too which
How do I correct this printing out copied files from directory in Unix Bourne Shell?
So i need to write a Unix Bourne Shell to to copy all the files from the directories named dir1 and dir2 into a new directory named dir3. The script first copies all the files from dir1 into dir3. The script then copies every file from dir2 to dir3 subject to these conditions: if the file from dir2 is not
Bash script – delete old files
I have a script that uploaded a compressed file to an ftp, it is the code that I show below. This code works correctly, but I would like to adapt it so that once the file is uploaded, it deletes ftp files older than a week. Answer You can try this solution: Note: I have commented the Remove file line,
DNS Resolver does not contain answer
I’m trying to automate some of the tasks with python. I have to chcek if some domains are still in ours DNS servers. So searching through stack i found script with dns.resolver and tryied to suit it to my needs. So, the script looks like this: My domainfile.txt looks like this: And error message i recived is: Traceback (most recent
Find if a shell variable contains specific string and comment it
I want to write a script that looks for a variable and checks if it contains exact string and comment it if exists. I have tried using sed and grep but it hasnt worked for me yet. My script for deleting: JV_PAT contains the path were java in installed excluding the /bin JAVA_LOC = /data/jdk1.8.0_111/bin/java JV_PAT = /data/jdk1.8.0_111 My Output:
Switch to root user within bash script
Im currently logged in as admin and I want to edit the /etc/hosts file which required root access. I’m not able to make the changes. The script gets executed sucessfully but the changes arent made. My Script – Runs Sucessfully when executed from terminal sudo -s – switches to root without password when executed from terminal su admin – switches
Concatenating hardcoded directory and user-created text file adds root-level paths when it shouldn’t
I have written a script to allow a restricted user access to deleting files on a production webserver. However, to prevent fat-fingering issues leading to accidental filesystem deletion/problems, I have hard coded the base directory in a variable… But the final result is not properly creating the desired path from hard-coded directory + user paths if they have a *
Renaming JSON files based on their contents
I have loads of geographical json files with date_geohash.json name format and I have to convert them to date_latitude-longotude.json format. For example I need to convert 2017-03-28_u13hhyn.json to 2017-03-28_N52.76-E1.62.json. I’m trying to write a bash script to rename these json files using ‘rename’ and ‘jq’ (json query) utilities. Using jq I can extract latitude and longitude from the json files.
Single quoted full path files in a text file can’t do for loop processing mv: cannot stat … No such file or directory
I have a test file which contains a space-separated files that I want to move/delete. Example line: I want to move the files away to another directory in a for loop: But it gives me an error. Why? 2nd problem after this how could I move actually this file to the new place with included the original directory somehow in