Hi Experts,
i am completely new to scripting.i had a requirement where i need to add the time to name of the file and i need to get the latest file. in order to fulfill this i need a script. and my os is unix.so please help me guys
Thanks
Giridhar
Hi,
I am new to UNIX - i wrote this below script based on the requirement. But i am stuck at the concatenation (at the second last step of the code)
The below code is working fine till the concatenation(second last step) - I need to concatenate Hello to the "physId" e.g. - The filename is UM123456789.20150503 - i am extracting M123456789 and i need to append "HELO" to it at the end. But as per the below script - when i am using the concatenation, it is overwriting the M123456789 and the output thus becomes HELO456789. I am trying to get the output as - M123456789HELO - where am i going wrong?
on the terminal i checked - echo $0 and it gave -> /bin/sh. Hence i wrote the below code.
#!bin/sh
absolutePath=/abc/data/abc_unix/stg/decrypt/*.*
filepath=$(echo ${absolutePath%.*})
echo "$filepath"
filenameext=$(echo ${filepath#/abc*decrypt/})
echo "$filenameext"
file=$(echo ${filenameext#.*})
echo "$file"
extract_physId=$(echo ${file:1:9})
physId=$(echo ${extract_physId})
echo "$physId"
key="$physId"HELO
echo "$key"
hi,
I am newbie in Linux shell scripting.Can anybody help me to check the presence of file identified by variable in Shell scripting?
For example: I am reading the content of a file using while command as below:
"while read -r line
do
code block
done < file_name"
Now in this case every line in file gets stored in the variable 'line' one by one.Problem here is every line in the file is nothing but the file_path of another file say xyz.txt and I am checking presence of this xyz.txt file using below command:
if [-f $line]
as 'line' is the variable which stores file path of xyz.txt but it is not working. It is unable to check the presence of this xyz.txt file as i am addressing it with the variable 'line'.
Please help me.Thanks in advance.
Hi All,
Im trying to create a script which checks the creation time of a file and if it is more than ten minutes, send out an alert.
For ex : Creation date of file is 10:30 AM
current time is 10:45 AM
Then send an alert/ message.
This is the script i wrote below :
Code:
#!/bin/ksh
filename="/apps/log/file.txt"
if [ -f "${filename}" ]
then
createTime=`ls -lad "${filename}" | awk '{print $8}'`
echo "$createTime"
currentTime=`date '+%M'`
echo "$currentTime"
DIFF=$(( $currentTime - $createTime ))
echo "$DIFF"
else
exit 1
fi
I am getting syntax error on the subraction when i try to run this script . I can understand that creation time and current time is in different format thats y this error throws, but i dont know how to rectify it .
I need to find out if the file creation time is more than ten minutes.
Please help me in achieving this output.
Ok yes this is a homework assignment BUT I am NOT looking to have the answers given to me. I am in the 6th week of my first Linux class ever and we are in our few weeks of beginning scripting. I have some ideas of what to do or where to start but not many and no one to bounce any ideas off...we are using UNIX Bash shell so any others I have no clue. The scenario is that I need a script that searches all my users home directories for bad words. I need the script to report to the screen certain info like username and word found and path. It should ask a user if it is good or bad and if bad be put into a file of list of bad file names, if good remove from list and no longer flagged by the script. What I have so far is wanting to somehow do a loop. I do know that if I do a grep -r -e kill -e steal /home/* I get a list of what I need. I also know that the list is separated by delimiters which I can pipe to get a variable for the things I need. I also know that I can put it to a file with a > filename.txt
What I have no clue is how to start a loop that would do this...
for each line in filename.txt
UNAME=...
LOC=...
TXT=...
echo "Username: $UNAME, Line with bad word found: $TXT, and Path and file name: $LOC. Is this a BAD file? (Y)"
Read YORN
if ["$YORN" = "Y" ]; then
>> (line of text from grep) badfiles.txt
fi
Next or whatever goes there...sorry if this is crazy I just really need some direction. I am trying to learn so please don't give me the answer...that will do nothing for me and I will not be able to explain the code I came up with.
Dears,
I want to create script to rename multiple file names from unix date to date for example
filename_1421907815_department.txt
rename to
filename_2015_01_22_08_23_department.txt
Hello,
I apologize in advance for my limited UNIX scripting knowledge. I am new to it and really want to learn.
I am trying to write a bash script that updates a config file based on user input.
What is the best method for accomplishing this? I need it to prompt the user for two variables, find the location in the config file, and insert new text with the two variables.
I was thinking I could use sed to find the text in the config file where the new text must be inserted before and replace it with the new text, two variables, and same ending text as before. Example:
echo "1st variable?"
read variable1
echo "2nd variable?"
read variable2
sed -e "s|<the spot in the config file that needs new config>|sometext...$variable2_somemoretext...$variable1\n<the spot in the config file that needs new config>|g" config > config2
This works except variable2 is not inserted into the replace string, only variable1 is. This is the result in config2:
sometext..._somemoretext...$variable1
<the spot in the config file that needs new config>
If anyone can tell me why variable2 isn't working in the sed replace string, or if there's a much better way for accomplishing what I'm after, I'd appreciate any help I can get.
Please tell me for shell script..
I m writing the script.
In that script i written the 1 function and in that function i have to write the contents in existing file
so i write,
cat > /etc/puppet/manifests/init.pp
{
ensure => present,
}
.
But it caanot write the changes in ssh machine
so what i can do in my script?
Please help me...
Hi guys I just started learning Linux, Need some help writing the script for the following
1. An argument of the form-6 sets the script to display the first 6 lines of the succeeding file(s). the default should be 5.
2. Anything else of the form "-x" should produce an error message
3. For a file name, display the first _lines of the file
I have two files which has exact same number of lines.
I want first line of first file should be filename of new file and content of this new file should be first line of second file.
Then second line of first file should be filename of again new file and content of this new file should be second line of second file.
then third line of first file should be filename of again new file and content of this new file should be third line of second file.
and so on...
I am trying to do it using for loop but I am not able to create two for loops.
This is what I have done
Code:
IFS=$'\n'
var=$(sed 's/\"http\(.*\)\/\(.*\).wav\"\,\".*/\2/g' 1797.csv) # filenames of all files
var2=$(sed 's/\"http\(.*\)\/\(.*\).wav\"\,\"\(.*\)\"$/\3/g' 1797.csv) # contents of all files
for j in $var;
do
#Here I do not know how to use $var2
done
Please help.
Hi!
I wrote a script shell about changing IP of the httpd.conf from text file and saving a new httpd.conf file for all IPs in the text file. The code is below, Im using mremote on windows (RHEL Release 5.7), and getting this error:
./script1.sh: line 19: syntax error: unexpected end of file
Please help me about that error. Thanks!
(ps: line 19 is the last line in the code => done < "$filename" )
#!/bin/bash
DATE='date +%Y%m%d_%H:%M:%S'
NAME=httpd_ip_change
EXTENSION=conf
max=10
filename="$1"
while read -r line
for ((i=2; i<=$max; ++i ))
do
touch $NAME$i.$EXTENSION.$DATE
sed "s/<VirtualHost 10.11.92.81:80>/$line/g" ./httpd.conf > $NAME$i.$EXTENSION.$DATE
done < "$filename"