Skip to content
Advertisement

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

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.

Advertisement