ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am working on one script which I am unable to achieve and would need community help.
The below [should do] script does 2 things
I enter certain domains in $1
Then these domains are taken and parsed; done sanity check and entered in a temp file.
Then I already have one file /var/www/html/today.txt. So this tempfile get concatenated with today.txt and then uniq entries are added in final file.
This part is working fine
Now I am introducing one more function to avoid the double work. While entering the domains it will prompt for TAG. Now this TAG could be separate every time. Again same procedure will follow and new .yaml file should be created under /var/www/html/doms.yaml
While doing that I am stuck up at sorting out uniq entries and then "only those" newly added domains should get tagged per $tag and appended to /var/www/html/doms.yaml
One thing is "/opt/maldoms" will contain new domains or few domains may repated I want eventually an uniq entries in /var/www/html/doms.yaml but with different TAGS. Not sure where my logic is going wrong
Hey ok - The main objective for me is not to disturb the existing codes however the script is initially being used for 2 purpose one get those urls/domains and put it in a file i.e. /var/www/html/today.txt
Other it would prompt data operator to enter tag and build a separate dict.yaml file with the appropriate TAG appended. And this is not working.
TAG could be one ata time let me tell you
first circle
TAG: phishing
It would take all those domains and create the yaml file however next time again if new TAG is entered all those domains get tagged with new one and phishing wipes off.
Not sure if bash would be the first choice for this type of program, at first glance with perl you could reduce code considerably and use appropriate data types to hold values
Now bash 4 introduced associative arrays, so maybe you could use this feature and use whatever you want to be uniq as key
Following the logic of last post, you can use domains as keys and tag as values
Then adding domain / tag is a matter of adding new key/value pair to array
Well to be frank I am not coding pro neither have bash script expertise but writing small script to automate my most of the daily tasks.
@grail - Its just a file which is passed. Like my original script is saved as by name publish in /usr/sbin; Hence I am running
root@xxxxxxx:~# publish domains.txt
Well I definitely want to learn but again not being a pro and these script were originally written by someone else and I am just taking over and learning would not want to break anything. Though I can always copy the stuff and play with those.
and while the same script I was thinking it would prompt to enter the TAG like TAG: phishing
so doms.yaml would look like
"uai.projetosvp": "PHISHING"
"com.br": "PHISHING"
THis much is achived. While at the next run if new domains are entered again those might have different TAG and this is where I am failing
Lets say next run will containg
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.