LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need help writing a script (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-writing-a-script-893870/)

cpatno 07-26-2011 10:55 AM

Need help writing a script
 
Hello group, I need help writing a script, I am sure this can be done as a bash script but if someone wanted to do this in ruby or perl that would work just fine.

What I need to do is take a list of file names from my database, I then need to search in a directory and see if that file actual exists there, if it does not exist I need to be informed somehow.

Thanks in advance.

Wim Sturkenboom 07-26-2011 11:17 AM

So what did you come up with till now?

cpatno 07-26-2011 11:47 AM

Quote:

Originally Posted by Wim Sturkenboom (Post 4425682)
So what did you come up with till now?

I have no solution as of right now.

unSpawn 07-26-2011 12:11 PM

Bash scripting guides
 
Code:

function help() { echo "Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html
http://www.gnu.org/software/bash/manual/html_node/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/
http://wooledge.org/mywiki/BashFAQ?action=show&redirect=BashFaq
http://wooledge.org/mywiki/BashPitfalls"; }


cpatno 07-26-2011 12:17 PM

Quote:

Originally Posted by unSpawn (Post 4425728)
Code:

function help() { echo "Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html
http://www.gnu.org/software/bash/manual/html_node/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/
http://wooledge.org/mywiki/BashFAQ?action=show&redirect=BashFaq
http://wooledge.org/mywiki/BashPitfalls"; }


Seriously, you are going to RTFM me? It isn't like I asked how do I list all files in a directory, WTF. This is the newbie forum right?

unSpawn 07-26-2011 12:33 PM

To Wim Sturkenbooms question you responded you have nothing to show. Now he basically asked for any commands or (pseudo)code you tried, as that makes it easier for us to correct you, after all you asked for help and not somebody writing the script for you. Without any effort on your side it's hard to gauge what we should provide you with and hence I think it's prudent to start at the beginning.


Quote:

Originally Posted by cpatno (Post 4425739)
WTF.

Friendly advice: you're new here. Be careful who you think you can say that kind of thing to.
*Also it seems you marked his post as "unhelpful". If that's gonna be your attitude towards responses then that needs change.

//Note to all: with posts #6 and #7 the OP has received enough nudges wrt how he should progress. Please no more replies in the same vein.

TobiSGD 07-26-2011 12:35 PM

Yes, this is the newbie forum. That doesn't mean we will do your work. If you want to write a script read a tutorial about scripting. If you have questions about that you can ask here for further explanation, we will help you with that, but only if you show us that you will do something for yourself. If that isn't what you want feel free to ask for a paid programmer in the LQ Job Marketplace.

markush 07-26-2011 12:36 PM

Hello cpatno, welcome to LQ,

note that we have rules here, one of them is that we will not do other people's homework.

We expect that you post some code you have already written for your script. And then if you ask "this does not work, can you help me", you will get help.

btw, nobody here has learned Linux only by asking other people to do his/her work/homework and please note that we are all volunteers, if you need professional help you may (for example) hire a freelancer.

To your question, you did not mention which database you're using, which language/tools you should/would use and so on. Do you have an idea by yourself how to write such a script?

Markus

cpatno 07-26-2011 12:37 PM

I took Wim's question as "what have you been using up to this point" which is that I haven't. I have acquired this from someone who let this get out of hand so that is why I have nothing working at this point. To the question of what have I tried so far, I have been playing around with different things that I have googled but I have had no luck.

unSpawn 07-26-2011 12:39 PM

Quote:

Originally Posted by cpatno (Post 4425765)
I have been playing around with different things that I have googled but I have had no luck.

Cool. Just show us what you tried and where it failed.

hf2046 07-26-2011 12:40 PM

Quote:

Originally Posted by cpatno (Post 4425739)
Seriously, you are going to RTFM me? It isn't like I asked how do I list all files in a directory, WTF. This is the newbie forum right?

You know the saying... give a man a fish, feed him for a day... etc., etc.

Quote:

Originally Posted by unSpawn
Cool. Just show us what you tried and where it failed.

Exactly.

cpatno 07-26-2011 12:40 PM

I just don't have scripting experience, my expertise lies in other areas of IT. I know this would take someone all of 2 min to type out but while you guys ride around here on your high horses I will go elsewhere, thanks

MTK358 07-26-2011 12:43 PM

What's wrong with learning? This is a really good tutorial:

http://linuxcommand.org/writing_shell_scripts.php

If you really, really don't want to read the whole thing, at least check out chapter 9, it says how to check if a file exists there.

One thing about bash scripting is that it has a lot or quirks that newbies don't know about, which causes them to write code that seems to work for their situation but can actually do bad things when given certain types of input. So for that reason, I think that everyone who will be writing a bash script should at least read this:

http://mywiki.wooledge.org/BashPitfalls

markush 07-26-2011 12:52 PM

Quote:

Originally Posted by MTK358
So for that reason, I think that everyone who will be writing a bash script should at least read this:

http://mywiki.wooledge.org/BashPitfalls

@MTK358: an interesting link, thanks.

Markus

TobiSGD 07-26-2011 12:57 PM

Quote:

Originally Posted by cpatno (Post 4425769)
I just don't have scripting experience, my expertise lies in other areas of IT. I know this would take someone all of 2 min to type out but while you guys ride around here on your high horses I will go elsewhere, thanks

If you have no experience in scripting and also don't want to learn it you should say that to your boss, so that he can assign that task to someone who has experience or the will to learn. It makes no sense at all to come up with a solution that you are 1. not able to understand and 2. not able to maintain, if any changes occur. Has nothing to do with high horses at all.


All times are GMT -5. The time now is 07:20 AM.