Programming :: Command Line Works - Won't Work From Inside Bash Script
Feb 16, 2011
Writing script to create backup of file by adding datetime to file name. Basically test for file presence if there, cp with datetime then rm original cp works fine from command line but get cannot stat `full path to file': No such file or directory
Here are the errors: cp: cannot stat `~/html/CVP_dadamail/.dada_files/.logs/errors.txt': No such file or directory rm: cannot remove `...': No such file or directory
The for statement is a placeholder as I have same file to backup out of several directories. using "bash -x scriptname" -OR- inserting echos, I can see I've constructed the strings properly. Believing it might be related to the hidden directories, I tried setting the shopt "glob" options to no avail.
Ultimately I'll add the other directories to the for loop and then run this from a cron job, so if you see potential pitfalls knowing I'm headed in that direction...believe construct would be
I'm writing a Bash script to take IPTC keywords from a text file and write them, via Exiv2, to several (first batch is 100) JPEG files in a single directory. The script has one while loop inside another while loop, both terminated, but I'm pretty sure that's not my problem. I think it's how I'm incrementing the "counter" variable, although it could also be the method of parsing the text lines from the file (using cut with delimiters that have worked fine in simpler scripts).
Here's the code as I've worked it up to this point.
And yes, "keywords" checks out in Crimson Editor, Emacs GUI and nano as an ASCII file with UNIX line endings. No issues on that score.
Feeding each line consecutively into a terminal (excepting the exiv2 command) works fine: each variable echoes with the part of the text line used as a variable value as it should, even when the b variable is incremented the quick&dirty way (up arrow three commands and hit enter).
Running the above script in eval mode (sh -x) stalls after setting the b variable to one and reading in the first line of text. I'd like to know why. I'd also like some advice on another reliable method of parsing the read-in lines.
I'm having problems with bash quoting. Maybe someone can tell me what's going on.. Basically, I need to create a command line inside a bash script that contains arguments that contain spaces and bash variables that need to be expanded.
I know that using alias I can run a whole command with a shortcut. But my requirement is to use parts of a long command and in between I have to pass some user defined values. E.g. Suppose I have to routinely copy a directory to another remote directory on a remote machine.The remote machine name is quite long as well as the directory path to which I want to copy the files into.So the command to do scp would look like this[URL]Now I want to do some sort of aliasing (say "ecp") so that I just need to pass the source_directory name and the ecp command and do my job
im pretty sure this is a remedial task for many of you but im having an issue with arrays from a shell script being accessed in an awk command. im pretty good with shell scripting but i am embarrassingly unfamiliar with awk. so here's the meat of the script...
I am trying to take an input file of ip addresses and corresponding netmasks and put it into a format to be loaded onto a juniper switch. the result should look something like this.. x.x.x.x/netmask using the cidr notation. no matter what subnet is provided though, /32 always gets appended to the end of the ip even when it should be /16, /24, etc... also, the cisco part works fine so that doesnt need any attention.
I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened.
bash 3.1.17(2) I'm trying do write a shell script which must operate on each line of an ASCII text file. So, all the code must be inside a loop, and inside the loop, the first thing should be to read the next line from the file. I have the bash read command. But it reads from stdin. Any way to make read from a file?
I'm trying to make another file annotation script a little speedier than it has been by the up-until-now proven method of checking the last four characters in a filename before the "dot" (eg .jpg, .psd) against a list of known IPTC categories and Exiv2 command files. It occurred to me that if one script generated a list of files in directory foo, and the same or another script sorted that list by that four-letter tag,then that list could be used(instead of a for/do/done loop on the real files in the folder) by the command-file-matching script to "vomit out" which annotator file would go with file nastynewfile.jpg, f'r'instance. The script I had been using for this task looks like this:
while read 'line'; do sp=$(echo $line) vc=$(echo $sp | cut -d"," -f1) cv=$(echo $sp | cut -d"," -f2)
Where I seem to be stuck is with how to sort the lines in templist, which may be any number of different lengths, from back to front. sort -k looked promising, except it seems only to work the other way round. I thought of invoking a
q=$(expr length $line); echo $q n=$[q-8]; echo $n
kind of thing, but that presented the problems of how to sort by those, how to tell sort where to find them (grep?) and how to "stitch them back in" to the original list, which is what I want to sort in the first place.
I have two Roboards that need to communicate with one another. I have sucessfully installed Ubuntu 9.04 using the 386 kernel based on instructions found online.I can use the GUI to set up an Ad-Hoc network using one Roboard ("Create New Wireless Network"), call it Manet, and connect to "Manet" using the GUI on the other Roboard and ping/ssh between the boards. However, when I try to create the same wireless network using the command line using:
ifconfig wlan2 down iwconfig wlan2 key off essid 'Manet' channel 5 ap any ifconfig wlan2 up
I don't see any entry in iwconfig under "Cell". It keeps giving me "Not Associated"When I try to enter the same information on the other Roboard to try to connect to the network, it doesn't connect and under iwconfig, I don't even see any entry for ESSID. Could somebody please tell me why it works when I use the GUI and not the command line.
Does anyone know why Nautilus would allow me to login to a server but not display any files, but when I log in via the 'ftp' command-line binary, it works and allows me to display all the files, make directories, etc.? I was able to login via FileZilla too.
Here's part of the log: Code: Response:220 Microsoft FTP Service Command:USER ---- Response:331 Password required for ----. Command:PASS *********** Response:230-Welcome to the Alentus FTP server. Response:230 User ---- logged in. Command:SYST Response:215 Windows_NT Command:FEAT Response:211-FEAT Response:SIZE Response:MDTM Response:211 END Status:Connected Status:Retrieving directory listing...
Having an odd problem running a mysqldump via crontab. I have the script running on other servers and they work fine, so not sure how to actually troubleshoot, but the script looks like the following;
If I run it as a cronjob as root, it finishes in a second and a 20k file is there. If I run it from the command line as root it does the backup (takes a few minutes) but does complete the backup and can be unzipped and read successfully.
On checking some of what was written in 2005 I find most of it isn't still relevant (if it was then - I noted the w3m-js stuff mentioned in 2005 hadn't been updated since 2003).
Since then a couple of times I've looked into it but didn't make much headway but also didn't spend a lot of time on it. So far as I could tell from other posts I'd seen others hadn't either.
Recently I found out about Mozilla's SpiderMoneky js library and that it could be linked into elinks text browser and did same on my RHEL5 system.
I found Spidermonkey rpms in the EPEL (Fedora sponsored) repository: js-1.70-8.el5.i386.rpm js-1.70-8.el5.x86_64.rpm js-devel-1.70-8.el5.i386.rpm js-devel-1.70-8.el5.x86_64.rpm
I was able to download and install using rpm then compile elinks from source to include the above. Running elinks version after that shows the ECMAScript support is compiled into the new elinks binary. Also setting various ecmas* flags in the elinks.conf does have effect so clearly it is using them. (As opposed to another system where I use the original RHEL5 provided elinks RPM it complains about the ecmas* stuff being invalid options.)
It appears that by default it has this enabled but just for good measure I added:
set ecmascript.enable = 1.
Despite that when I pull up the page I see:
As a test I set the above to 0 on the off chance it was backwards and saw the same thing.
I then set the following:
set ecmascript.error_reporting = 1
On pulling up the page I now see a popup box:
A script embedded in the current document raised the
TypeError: Window.Focus is not a function
Does anyone have any idea what Iï¿½d need to do to deal with the Window.Focus message?
Essentially the site is a login page and even though I am able to input username and password after opening in browser when I tell it to POST it simply returns to the same login/password page.
The SpiderMonkey stuff from Mozilla when compiled into elinks is supposed to do that but given my results Im not sure if it is or not.
So, in finishing my nFlux slack current edition.I have set it up for users to do certain things in console and one of the things I want is a way to view slackbook-2.0 in runlevel 3 console.I cant find a pdf reader that works in command line mode and I cant figure out how to either convert slackbook 2.0 pdf into html/text Or find a slackbook download that is html or text?I tried converting it using pdftotext, which didnt work very well So, I need a command line pdf viewer or a converter that works good?
I want to write the date & time and a text string to a file from crontab.The following line works fine in the CL:echo $(/bin/date +"%F %T")" Some text" >> /home/me/foo.txtI installed in crontab and no text appears in the file that it is redirected to.The crontab entry looks like:* * * * * echo $(/bin/date +"%F %T")" Some text" >> /home/me/foo.txtTried a version to just write to stdout....* * * * * echo $(/bin/date +"%F %T")" Some text"No date, time or text appears at the command line
I've successfully mounted a network share with mount.cifs for the past 2 years using fstab with credfile.
Yesterday I moved this system to a new datacenter, but did not alter fstab or the credfile. The //server/share directory has IP rules in place, but this was updated with the new system IP while we moved the system. Now, I am mysteriously unable to automount //server/share. The local error is 13 (permission denied). The Windows server we are mounting returned a code that is defined as "username is valid but password is incorrect" Again - no changes (content or permissions) were made to my credfile or fstab entry. I've restarted netfs a few times, including rebooting the system twice. What is baffling is I can successfully mount //server/share via command line: Code: mount -t cifs //server/share /mnt/mycooldir -o username=foobar,password=1234
The username and passwords are identical in credfile and the mount options - I copied & pasted username / password from the credfile itself.
I am looking for a way to delete the currently entered commandline without wasting seconds on the "Backspace"-key.
For example I scrolled the bash history and have a long commandline that would execute when I pressed ENTER:
~$ aptitude search openssl | grep dev
But now I decide that I do not want to execute this command. Can I get an empty prompt fast without deleting the whole line with Backspace? On the Windows "cmd" you can just press ESCAPE and it is gone. This behavior would be what I want.
The question may seem trivial but this is bothering me for a long time now.