How to create bash
Anyone can gimme some sample to make this bash file..
i need 4 Job in a single bash. 1.download file using lftp with lftp scripts 2.mount the disk to a folder (i did this and its works) 3.copy the file that being download to the mounted folder. 4.unmount the folder. i did the no3. and its works... the other keep coming out with an error that "theres no directories" o.O here the sample 1. #!/bin/bash lftp -f /root/desktop/autoupdater/thescript.sh 3. #!/bin/bash cp /mnt/Temp /mnt/MyFolder 4. #!/bin/bash umount /mnt/MyFolder anything wrong on this bash script... hope some one can help me out.. X.x |
Have you verified that the directories you are trying to access actually exist? For #2, which disk are you supposed to mount? You don't show us the mount command you use, so it's hard to tell if you're getting this right. Also, we need to see the contents of /root/desktop/autoupdate/thescript.sh to see what lftp is downloading and where it is putting them.
|
Do you want something like by combining all these tasks:
Code:
#!/bin/bash Code:
#!/bin/bash |
Hi diskless.solve !
First, usually in a Bash script/program, a line that starts with the "pound"/"hash" character, that is the # character, is a comment. It's only the first line of the file, where # followed by ! is special. So if you want four commands in a single Bash program, you only need this line: Code:
#!/bin/bash The -x option to Bash turns on "debugging" output, which displays program commands while the bash program is running. The +x options turns off debugging output. You can see for yourself that #! on only the first line of the file, is special, by trying this Bash program. Put these lines in a single file, and execute the file: Code:
#!/bin/bash -x Code:
test_bash.bash Code:
chmod u+x ./test_bash.bash Code:
./test_bash.bash You'll see that both echo commands are displayed. If you change the -x on the first line to +x neither echo command will be displayed. That's because only the first line in the file is having any affect. The later line that starts with #! is just a comment, it has no affect in controlling the program. If it was having an effect controlling the program, it would turn off the debugging output, so you wouldn't see the second echo command displayed when the program runs. So your Bash program should look more like this: Code:
#!/bin/bash As has already been mentioned, we need to also have some idea what's in the lftp script, and you need to make sure that the directories you are trying to use, actually do exist. If there's something private in the lftp script, or in the mount command such as usernames, passwords, whatever, just replace them with things like $USERNAME $PASSWORD etc., we'll understand what you mean. We just need to make sure the structure of the lines in the lftp script file, and the structure of the mount command, are all correct. Hope this helps! |
rigor.. i did try these bash
#!/bin/bash lftp -f /root/desktop/autoupdater/thescript.sh mount ... cp /mnt/Temp /mnt/MyFolder umount /mnt/MyFolder but came out with the same error.. cant found the directories.. im using slackware... huh |
Again, is there a reason you do not show the complete mount command?
And as previously asked, what is the content of "thescript.sh"? |
If you're getting "no directories found" error, then better check all paths mentioned in your script, one-by-one.
Code:
~$ ls -la /path/to/file |
Ok let me explain... first this is the auto download game update for client server.. well actually its a Internet Cafe Server
here the sample for the script 1. #!/bin/bash lftp -f /root/desktop/autoupdater/thescript.lftp 2. #!/bin/bash mount -t ntfs-3g /dev/sdd1 /mnt/GAMES -o defaults,unmask=0 3. #!/bin/bash cp /mnt/Temp /mnt/MyFolder 4. #!/bin/bash umount /mnt/MyFolder For the script no2 its work without any error... no1 got an error even i use the set -xv usr/bin/2.sh: line 1: !#: command not found :No such file or directoryautoupdate/blabla.lftp for no 3 and no 4, it came out with bad Interper bash /usr/bin/3.sh: /bin/bash^M: bad interpreter: No such File or Directory whats wrong on the script actually.. :-? |
the ^M's imply that you used windows to edit the script. windows uses some non-standard way to signal the end of a line which gets messy when transferred to another pc.
|
try this, should work for the most part.
Code:
#!/bin/bash edit to add from those of you who know MUCH more about both linux and bash scripting then I, please comment on my little script so I can learn as well. Thank you all. |
^ the only thing i would have to critique would be use scp instead of ftp.
|
Quote:
If he is pulling a file from an other linux box id scrap 80% of my script and go pure rsync with ssh keys. |
So not to nitpick, but now that the mount has been included, apart from the editing in Windows, the obvious issue around the error being received would relate to:
Code:
# you are mounting |
Please forgive this message...I thought I saw another issue with the script, but I finally realized it may have just been the control-M's. Unfortunately, there doesn't appear to be a way to completely delete my message...
|
All times are GMT -5. The time now is 12:56 AM. |