scripting,rhel,grub , Use `grub-md5-crypt` in a script where user is prompted for password to encrypt


Use `grub-md5-crypt` in a script where user is prompted for password to encrypt

Question:

Tag: scripting,rhel,grub

As you already know from title, I want to configure an encrypted password for grub in /etc/grub.conf. I want to use a single script, where I will use grub-md5-crypt, enter my password that I want to encrypt, and sed that encrypted output in /etc/grub.conf. Second part is fine for me. but how to handle password prompt in the script:

[[email protected] ssh]# grub-md5-crypt 
Password: 
Retype password: 
$1$3L3j7$lkZs92MnlmQkVYiCH9dtJ.

How can I automatically save the encrypted password in a variable or manage it somehow, so that in the next line of my script I can sed it like this:

sed -i '/^[# ]*timeout.*/a $hashedpwd/' /etc/grub.conf

Please help


Answer:

Hashvalue="$(echo -e "[email protected]$$w0rd\[email protected]$$w0rd" | grub-md5-crypt 2>/dev/null | tail --lines=1)"


Related:


Conditional formatting VBA scripting (not IN excel)


vba,scripting,conditional-formatting
I've been developing a script that runs through a Txtfile, retrieves certain references, stores these refs in a variable in the form of ('ref1','ref2','ref3',...) so that after retrieving these refs I can query our database to retrieve 10 columns from the database. I add this result to a excel file,...

Checking Blank User Input in Batch file (No Input) [duplicate]


windows,batch-file,cmd,scripting
This question already has an answer here: set /p empty answer crash 1 answer So, I am asking the user to make an selection. The point of this question is to catch if the user hit just entered without any input. My plan is to find out if the...

Error while executing lsof from bash script


linux,bash,shell,scripting
I am trying to check for the process which are running on a particular port and if present kill them, as i have to start another process on that port. Below is my code snippet. #!/usr/bin/env bash TEST_CASE_PATH="$HOME/Projects"; #kill Previous Process Running on port 9130 OUTPUT="$(ls -1)" echo "${OUTPUT}" #...

BIOS level programming


scripting,boot,bios,low-level
I am trying to write a script that is executed before Windows is booted on my Computer. I have already developed a simple Linux bash script to accomplish this, but I would like to improve and take it further. The problem with using a Linux script is that it adds...

Deleting upto a line


bash,perl,shell,sed,scripting
I have a line that looks like: foo cat dog = -48.34277635 foo(horse->0) = -60.34277635 and I only want the last set of numbers: -60.34277635 The line is formatted with that exact spacing. I've looked everywhere for a simpler solution, but I can't find anything without chopping the file piece...

Populating a zenity list with results from mysql


bash,shell,awk,scripting,zenity
I'm doing a small project using BASH for a "Phone Book". It stores the data in a mysql database and uses a temporary file to work with the Selects. I'm using zenity visual interface, so I want to display the data stored in the database using the Zenity List Dialog....

Is it possible to run command “route -n” specifically for a NIC


linux,shell,scripting
I am fairly new to linux I wanted to ask if its possible in linux commands to run a "route -n" command to retrieve information for a specific NIC. E.G route -n ether0. Because currently it shows me for all the NIC's but what if I want just for one?...

Script to get List of logged in users


linux,shell,scripting,terminal
I'm writing a Shell script to get a list of logged in users, i want to show a list like this one : The user AAA is on tty3 The user BBB is on pts/0 Here's what i've written so far : echo "The user " | who | awk...

interpreting a script through F#


scripting,f#,interpreted-language
I really like F# but I feel like it's not succint and short enough. I want to go further. I do have an idea of how I'd like to improve it but I have no experience in making compilers so I thought I'd make it a scripting language. Then I...

Passing argument function not working


bash,shell,scripting
valid() { if [[ "$1" = "0" ]]; then echo "Pass a file name as argument" exit 1 fi } valid if [ -f $1 ]; then echo "$1 exists" else echo "$1 doesnt exist" fi In the above example, the vaild() function is not working, why so? When a...

Bash Case statement: check whether string ends in number


bash,scripting,numbers,case,ends
I'm writing a script and I'm kinda stuck at the following part: Inside a case statement, I want to check whether or not the "--sn" command is followed by a number (1-254). I thought i'd just use --sn*, but apperently * doesn't work for numbers? case "$1" in --sn* )...

RHEL - can't sudo from script


linux,rhel
I have a script where I'm trying to change user (from root) on boot. In /etc/rc.d/rc.local, I've changed it to cd into the script dir and execute it. It all works except for when it tries to execute: sudo -u newuser ./myscript.sh I get an error message: sorry, you must...

Using a bash script to apply another script to every file in a directory like a matrix


bash,shell,matrix,scripting,file-handling
Let's say in my directory I have five files. Files: 1,2,3,4, & 5 I have a script that will do a mathematical process to compare two files and I want to use this script on every file in the directory, example below. compare file 1 to 2,3,4, & 5 compare...

Adding up certain values in a Column for certain Rows USING AWK


linux,shell,awk,scripting
I want to sum up the values in Column 4 for the Rows whose Column 3 is equal to 1 using Awk for the data given below. 13.804 2 1 0.128 14.10683054308584 13.805 4 1 0.1 16.404063320609485 13.845 4 1 0.1 18.88784810910845 13.887 3 0 0.5 15.885403793537332 13.900 2 1...

How to use multiple classes in multiple files in scripts?


groovy,scripting
I need to make a standalone Groovy script that does not require compilation and runs without Groovy installed. It works well, but it fails to recognize any other script than the main script. My folder structure is the following: libs\ groovy-all-2.4.3.jar ivy-2.4.0.jar src\ makeRelease.groovy ReleaseHelper.groovy I am launching the script...

Running a script of any language in Ruby


ruby-on-rails,ruby,bash,shell,scripting
I can execute shell command in Ruby using: def run(code) %x[ #{code} ] end I can also evaluate Ruby script in Ruby using: def run(code) eval(code) end Is there a way to blindly execute/evaluate code as a shell script, regardless of the language? I'm thinking of including #!/bin/bash or #!/usr/bin/env...

How to get the last parameter in shell [duplicate]


linux,bash,shell,scripting
This question already has an answer here: Getting the last argument passed to a shell script 21 answers I'm wondering how to obtain the last argument passed to a bash function, like this: #!/bin/bash function hello() { [email protected] # all arguments n=$# # number of arguments first_arg=$1 # argument...

Can I set specific numbers in bash instead of a sequence?


linux,bash,variables,scripting
I'm currently trying to make a script in bash that uses some specific numbers. It's for a different program but for the example, I'll use this basic ping script. In this example, the script would ping 192.168.1.215, 216, etc. up to 225 for i in `seq 215 225`; do ping...

Why do we need to make file executable when using shebang?


shell,unix,scripting
I am a unix newbie and exploring the functionalities of shebang line. For example, let's say I have a program program.py to execute. One way to execute is to directly call the interpreter command: python program.py If using the shebang line, I will include: #!/usr/bin/env python at the beginning of...

Using excel as inputfile in vba (scripting - non MS OFFICE)


vba,scripting
I'm developing a script in VBA (inside a workspace, not MS office program) that needs to use a small excel file as input. I want to use the data in the excel file and load it into a 2D array so that I can make decisions within my script based...

Linux bash scripting: sorting a list to use


linux,bash,shell,sorting,scripting
I'm implementing a sort-function in my script, but I have trouble in doing so: what I want to achieve is the following: bash script --sort 44 55 1 23 44 output: Pinging to 192.168.1.1 succes Pinging to 192.168.1.23 failed Pinging to 192.168.1.44 failed Pinging to 192.168.1.55 failed The pinging and...

Converting a Shell Script Into a *.app File


osx,shell,scripting,executable,desktop
Using Automator.app and Platypus.app, I have been able to bundle a simple shell script I created to power cycle wi-fi on my MacBook Pro. Both resulting apps run properly, but have one glaring issue that I want to correct: The apps reference the shell script from outside of the program....

Rearranging a csv file


bash,shell,csv,awk,scripting
I have a file with contents similar to the below Boy,Football Boy,Football Boy,Football Boy,Squash Boy,Tennis Boy,Football Girl,Tennis Girl,Squash Girl,Tennis Girl,Tennis Boy,Football How can I use 'awk' or similar to rearrange this to the below: Football Tennis Squash Boy 5 1 1 Girl 0 3 1 I'm not even sure if...

How to use mock with epel-7


fedora,rhel,chroot,epel
I have been trying to create a chroot for epel-7 using mock. Following this link: http://miroslav.suchy.cz/blog/archives/2015/05/20/why_mock_does_not_work_on_el_6_and_el7_and_how_to_fix_it/index.html I changed my .cfg file. Now when I tr to create chroot, I get the following error: sudo ./create_chroot.sh epel-7 INFO: mock.py version 1.2.8 starting (python version = 2.7.8)... Start: init plugins INFO: selinux...

Reading rsync source from file results in improper parsing of file names with white space


bash,shell,unix,scripting,rsync
I wrote a simple script that searches through a specific directory defined by the variable "SCOPE" producing a list of directories that were modified within the past 24 hours printing them to a temp file. The first line of the file is deleted (to exclude the root level of the...

Expect script for checking ssh connection for a list of ips


shell,ssh,scripting,expect
Can anyone help me in creating an expect script to just do an SSH on a list of servers and check if it was fine. I do not need to interact, do not need to fire any command on each server, I just want to do an ssh and come...

RHEL Java application - specific name instead of generic java process


java,linux,process,rhel
I have a custom Java application running on my RHEL machine. I am running this Java application from a bash exec script with all the parameters and options appended. As a result, my Java application gets a generic name "java" in the system processes which is not useful for me...

Iterating over dates with a bash loop in bash — for (( … )) not working correctly


linux,bash,date,scripting
I am trying to create a list of dates. This script below works with simple dates with no spaces. datestart=20130601 dateend=20130705 for (( date1="$datestart"; date1 != dateend; )); do date1="$(date --date="$date1 + 1 days" +'%Y%m%d')"; echo $date1; done When I use a data string like (which contains WHITE SPACE) datestart="2013-06-01...

Unable to start postgresql service in Redhat linux 7


postgresql,rhel
I have installed postgresql 9.4 on Redhat 7 server.It was installed through postgresql-9.4.3-1-linux-x64.run. It displayed a clear message"postgres is installed your machine". Now when I login as su - postgres It doesn't ask for password and goes to bash prompt. If I type psql displays "command not found". When I...

Detecting corrupt characters in UTF-8 encoded text file


regex,encoding,awk,utf-8,scripting
I have a text file that was edited with the wrong character encoding and thus has some mojibake and corrupt characters in some of the strings when I open it using UTF-8. What scripting language would be the most efficient at detecting these corrupt characters? Perl is not an option....

Compute checksum on file from command line


linux,shell,scripting,checksum
Looking for a command or set of commands that are readily available on Linux distributions that would allow me to create a script to generate a checksum for a file. This checksum is generated by a build system I have no control over by summing every single byte in the...

Add “-I” flag to string of paths in bash


bash,shell,scripting
Having a string of space separated paths, relative or absolute, example: /aaaa/bbbb/ccc /ddas/sdsa/dasd ./dasd/dsd dasd/dsda/dsd dsd/dsad/erer/rerer ../dasd/dsad ../../sdasd/sdsd How can I process this in bash in order to prepend every one of these paths with -I? Example output should be: -I/aaaa/bbbb/ccc -I/ddas/sdsa/dasd -I./dasd/dsd dasd/dsda/dsd dsd/dsad/erer/rerer -I../dasd/dsad -I../../sdasd/sdsd Thanks Edit for...

Looping variables


perl,scripting
I'm working with perl to make a script that will work with Dot products/assorted vector math. I've got a working script ( Still very much in progress/needs refinement ) that will do what I ask. #!/usr/bin/perl use strict; use warnings; use diagnostics; use Math::Vector::Real; use 5.010; use Math::Trig; my $source...

Using Gawk and Printf in a Bash script


bash,scripting,printf,file-handling,gawk
I am trying to separate a file into smaller files with gawk and rename the smaller files in order from the original file. for i in *.txt do gawk -v RS="START_of_LINE_to_SEPARATE" 'NF{ print RS$0 > "new_file_"++n".txt"}' $i done The output gives me: new_file_1.txt new_file_2.txt ect... I would like the output...

Expand ~ in Bash [duplicate]


bash,shell,scripting
This question already has an answer here: How to manually expand a special variable (ex: ~ tilde) in bash 8 answers I tend to visit the same directories during the course of a workday. Using the dirs -v command I can keep a list in a file dirs -v...

Execution Success, but no Results?


java,javascript,google-apps-script,scripting,google-apps
So, i'm working on creating this approval workflow for google forms. I'm new to this, I've searched online and read through some tutorials as well as google's but most of the stuff that I have seen has been deprecated. I think i have my triggers current, they're set to onformsubmit...

Parsing the text file line-by-line using batch script (batch file)


windows,batch-file,scripting,cmd
So, I am programming in the batch script and I came across this issue. The following code will take yourwords.txt file and parse it. The existedWord variable will have the last word of the text file. So, everytime when I run this program it will only compare the user's input...

What are valid input DATE formats for the (Linux) date command?


linux,bash,date,scripting
The following command generates the date for the next day: date -d "20150615 12:00 +1 day" +%Y%m%d 20150616 I would like to specify my own INPUT date format, such as: 2015_06_15 But the date command does not like this format and complains about invalid date: date: invalid date '2015_06_15 12:00...

searching a specific word from a list of words in batch file


batch-file,cmd,scripting
I have a %list% variable which has words (see the code) and I want to search a word which ends with letter 'Y' (ignoring the case-sensitive) and which starts with the last letter of user's input. User input would be any valid word. Once I find that specific word then...

Based On Styling Indesign Javascript Scripting CC


javascript,scripting,indesign,jsx
I would like to know how I can set ( either directly or some other alternative method ) the style property of "Based on" using javascript within adobe InDesign CC. If I could also ask for documentation leading to an answer for reference it would be immensely appreciated. My code:...

bash functions returns “command not found”


bash,shell,scripting
I've been trying to get this function to work without returning errors, but so far I'm unable to figure out what the problems is. I'm using $(report_home_space) to insert the contents of the functions on a small bit of hmtl but keep getting the error: report_home_space: command not found on...

Can I make _Assert write to console instead of a message box?


scripting,automated-tests,autoit
I am writing a script in AutoIt to test a windows application, and I am using the _Assert function to verify certain actions. In the documentation I found there is a parameter to say whether or not the script should end if an assertion fails, which is great because in...

How to make gnuplot to NOT plot multiple lines?


plot,scripting,gnuplot
I am plotting some data and I am getting multiple lines streaking across the plot. There should be one line, so I imagine that gnuplot is trying to fit the data and is joining points or something in a strange way. How can I get gnuplot to plot one like...

Copy file from one folder to another and then rename using current date/time and new file ext using PowerShell or Python script


python,windows,shell,powershell,scripting
I do not have any experience with PowerShell scripts so I need some help to create a simple shell script. The shell script needs to do the following: The script will look for a file name with .upl file extension in the directory M:\ProgramData\Aspect Software\Unified IP\Advanced List Management\tenant1\xfer\CRM_Upload.upl. The shell...

Finding the average of a column excluding certain rows using AWK


linux,bash,awk,scripting
I want to calculate the average of the 5th column (last column) excluding the rows with the value "9999". Would appreciate your feedback. 77.300 16 1 3.6112914285714268 9.4 77.300 16 2 -0.001737142857145102 20.0 77.300 16 3 5.1570742857142857 8.9 77.300 17 0 3.6112914285714268 8.9 77.300 17 1 2.9484342857142849 11.7 77.300 17...

Running rsync as root: Operations Not Permitted


osx,bash,scripting,permissions,backup
World! I have a backup script that would run rsync for every user and will archive their /User/user folder onto our shared drive. Running into an interesting problem with rsync: when executing the script as "sudo" from the shell as the current user I'm unable to preserve the permissions of...

Local file existence condition in bash FTP script


bash,scripting,ftp,local
I want to get a file from a server conditional on the non-existence of the file in the local directory. In the final script there will be many files but here is an example just using one. I'm trying this: #!/bin/bash HOST='a.b.c.d' USER='anonymous' PASSWD='pass' ftp -n -v $HOST << EOT...

While loop in bash using variable from txt file


linux,bash,rhel
I am new to bash and writing a script to read variables that is stored on each line of a text file (there are thousands of these variables). So I tried to write a script that would read the lines and automatically output the solution to the screen and save...

find the lines where sequence/sorting is broken in linux


linux,sorting,awk,scripting
I have a log file which contains lot of logs and first column contains the epoch time stamp, Ideally they should be in sequence/sorted. however if something goes wrong in system timestamp resets to some default value and sequence breaks and restarts. I am trying to find the lines where...

Rename a bunch of PNG images with “.jpg” extension to “.png”


image,bash,scripting,png,jpeg
So I have a folder with thousands of image files, all of them saved as .jpg. The problem is that some of those files are actually PNG image files, so they don't open in a lot of programs, unless I manually change their extension to .png. For example, the Ubuntu...