Hi im currently writing a Oracle 8 Kickstart file for our company and i need to automatically create a file after installation and write in it. This is what i tried
cat <<\EOF >>/etc/sysctl.d/disableipv6.conf
net.ipv6.conf.all.disable_ipv6 =1
net.ipv6.conf.default.disable_ipv6 =1
EOF
%end
but it somehow messes up because the file created looks like this
'disableipv6.conf'$'\r'
Related
I'm struggling in trying to create a script in Linux (Terminal-Bash) which is automated and when run it will ask for a input and when that input is added it will create sequential files.
See below:
when script is run, it should show
Which country are you from?
I enter Brazil and wish to see:
Data entered: Brazil1, Brazil2, Brazil3.....Brazil 10
The script needs create a batch of 10 each time it is run i.e.
Which country are you from?
I enter Canada and wish to see:
Canada1, Canada2, Canada3.....Canada10
If brazil entered again: Brazil11, Brazil12....Brazil20 and Brazil21, Brazil22....Brazil30 etc
I do not want to hardcode the numbers, automation is required to create them each time.
**Testing:
**
I have created the script by:
Touch test.sh
I have tried to edit the script by:
vim test.sh
In vim I have made the below changes:
#!bin/bash
echo "Which country are you from"
value=country
value{1..10}
Save vim, when executing script I get this message:
test.sh: line 4: value1: command not found
Can someone please help with the script? I'm completely new to linux and trying to best understand how to create the simplest and most effective process.
Thanks in advance.
This script is pretty straightforward to implement. You need to use the read command to read user input in. You can use the while loop with -f to test which files already exist, and then finally the for loop to create those files
#!/bin/bash
echo Hello, what country are you from?
read user_country
n=1
while [ -f "$user_country$n" ]
do
let "n+=10"
done
for ((i=0; i<10; i++))
do
file_num=$((i + n))
touch "$user_country$file_num"
done
I am currently working on a little script for the "nslookup"-command and in my testing I encountered a problem I don't understand. In my script a .txt file is automatically created and the user can input some text to it if he wishes to. He can also delete specific lines in the document. I tried writing it with "sed" but it doesn't seem to be working correctly.
Here the menu from the terminal output:
Domains:
1) new_domain
2) domain
3) Create new Domain
4) Delete a Domain
5) Quit
Input>
The first two numbers also representing the line of each text.
The code for deleting a domain is the following:
filename=domains.txt
old_filename=domains_backup.txt
read -p "Which domain-number shall be deleted?: " num_input
mv $filename $old_filename
sed "/$num_input/d" < $old_filename > $filename
rm $old_filename
But when executing that script and the user wants to delete line 2 (domain) the text-file remains the same and is not updated.
When I try the same only using the terminal everything works fine.
Is there something I'm missing?
To delete a line by its line number you will want to use $num_input d rather than /$num_input/d : the second one matches lines that contain $num_input.
As a side note, if you use GNU sed you could let it handle the backup :
sed -i.backup "$num_input d" domains.txt
This would create a copy of the untouched domains.txt as domains.txt.backup (or whatever suffix you specify after -i) and update the domains.txt file.
Assume you have a file called “heading” as follows
echo "Permissions^V<TAB>^V<TAB>Size^V<TAB>^V<TAB>File Name" > heading
echo "-------------------------------------------------------" >> heading
Write a (single) set of commands that will create a report as follows:
make a list of the names, permissions and size of all the files in your current directory,
matching (roughly) the format of the heading you just created,
put the list of files directly following the heading, and
save it all into a file called “file.list”.
All this is to be done without destroying the heading file.
I need to be able to do this all in a pipleline without altering the file. I can't seem to do this without destroying the file. Can somebody please make a pipe for me?
You can use command group:
{ cat heading; ls -l | sed 's/:/^V<tab>^V<tab>/g'; } > file.list
I have the script that creates some .html and .txt files every day. But now it is only one file html and txt with changed content, I need every day a new html&txt file with date oof creation in the file name like : index_22-05-2013.html , i have these variables in shell script:
DESTINATION_HTML="./daily/html/index_$(date +"%F").html"
DESTINATION_TXT="./daily/txt/index_$(date +"%F").txt"
and a line in shell script that running one python script and creates html file
python `somescript.py` -m ${FILELIST[0]} ${FILELIST[1]} > $DESTINATION_HTML
and i`m getting this file created:
index_$(date +"%F").html
what i must to do to get this file name : index_22-05-2013.html
Sorry, I am not following you, but since
echo "index_$(date +%F).html"
outputs index_2013-08-20.html instead of index_22-05-2013.html which is what you need, you probably want to use this command instead:
echo "index_$(date +%d-%m-%Y).html"
Hope it helps! :)
I'm trying to create a cron job to create mysql backups. I would like to be able to first check how many files are there in the directory and if there are 5 or more remove one (the oldest) and create a new mysqldump. I know how to create the mysqldump, but not sure about the condition. I'm planning to store the procedure in the .sh file and trigger that file once a day with the cronjob.
Could someone show the example of what the procedure should look like?
You could wrap the following in a shell script
for file_to_delete in `ls -1ta test* | tail --lines=+6` ; do echo "ENTER_CMD_HERE $file_to_delete" ; done
where
- test is name of file (replace it with path + name of the mysql bkp files)
- replace ENTER_CMD_HERE with say rm