Sponsored Content
Operating Systems Linux Red Hat how to use if condition with sed command in BASH Post 302632823 by spacebar on Monday 30th of April 2012 10:59:15 PM
Old 04-30-2012
This is a simple script that should do it for you:
Code:
#!/bin/bash
const='tinker panic 0'
if [ -e /etc/ntp.conf ]; then
  grep -q -e "$const" /etc/ntp.conf
  if [ $? = 1 ]; then
    echo "$const  ; not found but will be inserted as first line!"
    sed -i.bak '1 i\tinker panic 0' /etc/ntp.conf
  fi
fi
# Add '#' to beginning of line if it is not already there
sed -i.bak \
    -e 's/^server 127.127.1.0$/#server 127.127.1.0/' \
    -e 's/^local clock$/#local clock/' \
    -e 's/^fudge 127.127.1.0 stratum 10$/#fudge 127.127.1.0 stratum 10/' /etc/ntp.conf

hth
This User Gave Thanks to spacebar For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash: if condition as variable

How can I use a variable that has the conditions for the if statement stored in it? my test script condition=" || || " if "$condition" then echo "true" else echo "false" fi output $ ./test2.sh ./test2.sh: line 3: || || : command not found false (2 Replies)
Discussion started by: curlee2002
2 Replies

2. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

3. Programming

if condition in bash

Hi, I have meaning to include an if condition statement in my code to check the directory for existing output files and if its existing i want the program to delete it before doing the succeeding command. i just dont know the correct syntax for it. thanks much guys, this forum has indeed been very... (4 Replies)
Discussion started by: ida1215
4 Replies

4. Shell Programming and Scripting

[Solved] SED - Bash - Inserting multi Tab character in the command

Hello. I am using : sed -i -e '/§name_script§/a#'"${MY_TAB11}"'# \ #'"${MY_TAB1}"'The Standard way'"${MY_TAB7}"'# \ #'"${MY_TAB1}"'==============='"${MY_TAB7}"'# \ ' "$CUR_FILE" Is there a better way to define "MY_TAB7","MY_TAB11" in other way than : MY_TAB1=$'\t' MY_TAB2=${MY_TAB1}$'\t'... (2 Replies)
Discussion started by: jcdole
2 Replies

5. Shell Programming and Scripting

Add another condition to bash for when not met

In the below I can not seem to add a line that will add Not low if the statement in bold is not true or meet. I guess when the first if statement is true/meet then print low, otherwise print Not low in $(NF + 1). I am not sure how to correctly add this. Thank you :). if(low <= $2 && $2 <=... (5 Replies)
Discussion started by: cmccabe
5 Replies

6. Shell Programming and Scripting

Creating a condition on a bash script

I wrote a code to find codons in a DNA string. The only problem I have is how do I make the code only work for a file with DNA. This means the file only has the characters a,c,g,t and no white space characters. (3 Replies)
Discussion started by: germany1517
3 Replies

7. Shell Programming and Scripting

Executing sed command inside a bash script

I want to run commands inside a bash script. An example is I want to pass the command in a string as regexp as an argument to the script, then run sed on the bash variable sed.sh regexp sed.sh "-i \"s/<p>//g\"" then call sed "$regexp" $fl (3 Replies)
Discussion started by: Kangol
3 Replies

8. Shell Programming and Scripting

Need bash script to use a sed command as a variable

I need to be able to use a sed command as a variable in a bash script. I have the sed command that almost works the way I want it. the command is sed -n '/inet/,/}/p' config.boot This gets me this result: inet 192.168.1.245 } I need to get the IP address into a variable so I... (9 Replies)
Discussion started by: edlentz
9 Replies

9. UNIX for Beginners Questions & Answers

Condition in bash script

I want get from user and pass these parameters to bash script. script should copy files in user home directory. FYI: each file might be exist or not, might be one of them exist or four of them. Here is my script, it always copy file1 and seems only one of them execute! #!/bin/bash for... (6 Replies)
Discussion started by: indeed_1
6 Replies

10. UNIX for Beginners Questions & Answers

Sed, awk or another bash command to modify string with the content of another file

Hello everybody, I would like modify some strings using sed or another command line with the content file. For example: - {fqdn: "server-01" , ip: "server-01"} - {fqdn: "server-02" , ip: "server-02"} - {fqdn: "server-03" , ip: "server-03"} - {fqdn: "server-04" , ip: "server-04"} My... (4 Replies)
Discussion started by: dco
4 Replies
ntp.drift(4)						     Kernel Interfaces Manual						      ntp.drift(4)

NAME
ntp.drift - Network Time Protocol (NTP) drift file DESCRIPTION
When the NTP daemon (xntpd) is first started, it computes the error in the intrinsic frequency of the clock on the computer it is running on. This process usually takes about a day or two after the daemon is started to compute a good estimate of this (and it needs a good estimate to synchronize closely to its server). Once the initial value is computed, it will change only by relatively small amounts during the course of continued operation. The driftfile declaration should always be included in the ntp.conf file. This provides xntpd with complete path name to a file in which it can store the current value of the frequency error. That way, if the daemon is stopped and restarted, it can reinitialize itself to the previous estimate without spending time recomputing the frequency estimate. The ntp.drift file contains one line with the following format: freq_offset flag Specifies the nominal frequency offset. DO NOT modify this field. Specifies the method used to improve system clock accuracy. Specifies that xntpd runs a Phase-Locked Loop (PLL) algorithm to keep synchronized with other hosts. This is the default. Specifies the use of the PLL algorithm in the kernel. This requires the NTP_TIME kernel option. After the option is configured in the kernel, edit the ntp.drift file and change the flag value to 1. See System Administration for information on the NTP_TIME kernel option. FILES
Conventional name of the drift file RELATED INFORMATION
Commands: ntpdate(8), ntpq(8), xntpd(8), xntpdc(8) Files: ntp.conf(4) Network Administration, System Administration delim off ntp.drift(4)
All times are GMT -4. The time now is 12:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy