#!/bin/bash Get URL as argument url=$1 Get the file name from the URL…
- User
#!/bin/bash
Get URL as argument
url=$1
Get the file name from the URL
filename=url")
Download the page using wget and save to /var/www/
sudo wget filename
Change the file extension to .html
sudo mv /var/www/filename.html
- Assistant
This is a Bash script that takes a URL as an argument, downloads the page using wget, saves it to /var/www/, changes the file extension to .html, prompts the user to enter a new title for the page, and then uses sed to replace the title and meta tags in the downloaded file with the new title.
Here's how the script works:
- The first line specifies that this is a Bash script.
- The second line uses the "$1" parameter to get the URL argument passed to the script.
- The third line uses the "basename" command to extract the file name from the URL.
- The fourth line uses "wget" to download the page from the URL and save it to /var/www/ with the same file name as the original URL.
- The fifth line uses "mv" to change the file extension to .html.
- The sixth line prompts the user to enter a new title for the page and reads the input with "read".
- The seventh line uses "sed" to replace the text inside the tag in the downloaded file with the new title.
- The eighth line uses "sed" again to replace the text inside the tag in the downloaded file with the new title.
- User
thanks, so for the 7th and 8th line, instead of it replacing text inside the tag, I need it to just search the file for "Check out this ShareGPT conversation" and I need that text replaced with the text in the $new_title variable
- Assistant
Sure, you can modify the seventh line of the script to replace the text "Check out this ShareGPT conversation" with the value of the $new_title variable. Here's the modified line:
bashsudo sed -i "s#Check out this ShareGPT conversation#$new_title#" /var/www/$filename.htmlThis will search for the text "Check out this ShareGPT conversation" in the downloaded file and replace it with the value of the $new_title variable.
Similarly, you can modify the eighth line of the script to replace the text in the "content" attribute of the "og:title" meta tag with the value of the $new_title variable. Here's the modified line:
swiftsudo sed -i "s#<meta property=\"og:title\" content=\".*\"/>#<meta property=\"og:title\" content=\"$new_title\"/>#" /var/www/$filename.htmlThis will search for the "og:title" meta tag in the downloaded file and replace the "content" attribute with the value of the $new_title variable.
- User
I actually don't need the 8th line anymore :D
- Assistant
Alright, no problem! If you don't need to modify the "og:title" meta tag, you can simply remove the eighth line of the script. The modified script would look like this:
bash#!/bin/bash # Get URL as argument url=$1 # Get the file name from the URL filename=$(basename "$url") # Download the page using wget and save to /var/www/ sudo wget $url -O /var/www/$filename # Change the file extension to .html sudo mv /var/www/$filename /var/www/$filename.html # Prompt for new title echo "Enter new page title:" read new_title # Replace the text in the downloaded file sudo sed -i "s#Check out this ShareGPT conversation#$new_title#" /var/www/$filename.htmlThis modified script will still download the page from the specified URL, save it to /var/www/ with the .html extension, prompt the user for a new page title, and replace the "Check out this ShareGPT conversation" text with the value of the $new_title variable in the downloaded file.