Ubuntu :: Bash Script, Take User Input Then Use It As A Path?
Jan 29, 2011I'm trying to make a script to make it quicker to encode videos.
Code:
#!/bin/bash
echo "Type the path of the video file"
[code]....
I'm trying to make a script to make it quicker to encode videos.
Code:
#!/bin/bash
echo "Type the path of the video file"
[code]....
I am new to writing shell scripts. So, please bare with me. I am currently trying to write a shell script which will read the directory path as input from user and will traverse the Dir tree to find all available audio and video files. I have tried to write as much as I could but I don't know where I am making mistake as I get some files to be audio file which are actully tar balls. On the second note there are some files which video but script shows them to be audio. And, some video files are completely skipped. I am giving the shell script below so that you can see. I am using two external files as source which I am attaching.
Code:
#!/bin/bash
#Let's load the extensions that we want to search for
vdExt=$(cat vdExtList)
adExt=$(cat adExtList)
[code]....
I've written a bash script that allows a user to input a directory location to find out the size of the directory. However, if the user inputs a directory and finds its size then inputs another directory then wants to quit, the script asks the user numerous times if he wants to quit!! The script won't exit until the number of times the user looks at a directory is reached! What gives?
Here's the script:
Code:
I've been using python/bash to help myself automate things for a long time, however I am curious. One reason I use python more is because I don't quite know how to work with user input in Bash, such as getting it to ask for input and wait, and then placing that user input into a command.
Here's an example of a script I use from time to time for converting OGG video files into AVI.
How could I write this same script in Bash? Keep in mind I am mostly self taught, so I am by no means an expert programmer.
Code:
I have a script im having some problems with, what I need is to have the system generate a random password for me and use that password when creating new users to it.
System is Debian Lenny and script is in bash.
The program is znc. I have made it so that it will generate the random password on the shell but the problem is to use it in the bnc software.
To make a password there the command is znc --makepass and look like this:
My question is now if it would be possible to put in the script so it would "answer" when it need those passwords ? the random password that is generated is in a variable called $setpass and is NOT crypted.
Or is there any other software that would be able to generate that md5 string for me ?
How do you catch user input while the script is running? Or, how would you make two scripts run at the same time, but use input from one script to the other? The program I'm trying to make, echos text on the screen continuously, but while thats happening, I want the user to be able to input something, so the program can detect the input and display something else. So I thought maybe I could make two scripts run to do each task.
View 5 Replies View RelatedI'm trying to call a specific variable based on a user selection. For example:
Code: Select a file:
[1] foo.tar
[2] bar.tar
Enter a selection: I have already coded each possible selection to have its own variable. If the user selects 2 I need to select $SELECTED_TAR2, or if they select 1 I need to select $SELECTED_TAR1 and then do something like this behind the scenes:
Code: cp /home/user/$SELECTED_TAR2 /home/user/backup/$SELECTED_TAR2
I was thinking something like this:
Code: echo "Enter a selection: "
read -e SELECTED_NUMBER
cp /home/user/$SELECTED_TAR$SELECTED_NUMBER /home/user/backup
[code]....
I'm trying to create a backup script. For my second version, I want to make a GUI that will ask the user three things:
1. which folders should be excluded
2. where to store the backup
3. the user's email
I need to store this input, and later input the values into variables in my script. How do I go about doings this?
Here's a challenge I've been struggling for months with:
I have a bash script that reads URL addresses of our internal server and then executes some test commands on them. Something like this:
Code:
read -p "Enter URL: " url
sh execute-what-ever-to $url
After copy-pasting the URL the user taps the enter key and the script proceeds, but here comes the tricky part: I want this to work without the need to press the enter key after copy-pasting the URL.
"read -n" does not work in this case, as the URLs vary greatly in length. However, the URLs always end to the same string. They could be like "http://url1/END", "http://url2/END" and so on. So this ending string "END" could be theoretically used to recognize that the whole URL has been pasted.
I have a system setup script for my Slackware installations that pulls all packages and source files from another machine and sets everything up to be identical between machines. The script works as expected but make it entirely unattended. How do I make the bash script deal with automatically selecting "Yes" for, for example "Install x(Yes/No): " when prompted by a make file?
View 3 Replies View Relatedin bash scripting...say I want to take the input from a user via a question...I would do this:
Quote:
#!/bin/bash
echo "How large do you want this partition to be in GB (enter only the number)?" read PART_SIZE echo "You want your partition to be $PART_SIZE GB" But I don't want to echo it back to the screen, I want to add it to the content of /etc/fstab. I have been mucking around with sed to find the tmpfs partition in /etc/fstab and add the partition size attribute (this is to use the onboard RAM as a volatile partition)...but am not having any luck...
The portion of /etc/fstab that uses /dev/shm for the tmpfs partition is:
tmpfs /dev/shm tmpfs defaults 0 0
So, if a user says "24" GB to the answer (from above), how do I get it to automatically add that value to the tmpfs partition line in /etc/fstab? So it would look like:
tmpfs /dev/shm tmpfs size=24g,defaults 0 0
I understand that I would also have to come up with a way to put "size=XXg", which I could do with a copied over generic file before this action...then the script would have to find "XX" and replace it with the user's figure...
I'm creating a bash script to do some tasks for me. I would like the script to be run at a set time of everyday. My first question is if it is possible that if one of the commands in the script requires sudo, is there a way to get around it with out making sudo not require a password. Such as, is there a way to include the password in the script? If that is the case, I can always just set the file as read only by sudo. I've been looking for a way to do this, with no success. if I have a command that wants input, how do I give it to the program. For example, if I want to make a zip file that is encrypted, the command would go as:
Code:
zip -r example * -e
now how would I get the script to insert my wanted password.
I have a BASH script which at one point asks the user a yes/no question. I want to make it so that if the user types in an invalid input 3 times consecutively then the BASH script will echo an error and terminate with exit status 1.
View 9 Replies View RelatedI upgraded my OpenSUSE 11.2 KDE 4.3.5.x to KDE 4.4.2 and am having a couple of issues. Not sure if I am just a bit stupid or impatient figuring them out or what... In Amarok, I used to be able to input or edit the path name under Files (i.e. Browse Local Harddrive for Content). This allowed me to quickly copy and paste a location from Dolphin / Konqueror etc. into and from Amarok for quick access across multiple applications (Especially when sorting out things). Somehow this is either missing (Not possible anymore) or I am to impatient or stupid figuring this out.
View 2 Replies View Relatedkernel 2.6.21.5, slackware 12.0
GNU bash 3.1.17
Code:
As you can see, /usr/local/bin is in the path. However, bash does not look for nasm in /usr/local/bin.
If I am root, things go well:
Code:
I have a fortran program example call like this:
This call cant run my fortran program because they output to the screen that the file ' ' (empty) cant be loaded!
So the problem is that my program cant see the file in the long path name above ( the real name is a bit more longer). I try with shorts path names , and the program can run, reading the input file.
I googleit for this type of error and only found that bash have limits on the filenames and inputs, so i change them (/usr/local/linux/limits.h or some like) to a very high value (999) ,but no success.
I have some programs compiled into /opt/programname, and I would like to be able to execute them without typing the full path; I've tried with PATH=$PATH:/opt/*/bin, but with no luck;
View 4 Replies View RelatedI am trying to create a file, that has a variable assigned to it, in another directory. For some reason when I run the script it creates the file only in my pwd and I cannot for the life of me figure out why.My pwd at the moment is Desktop but it does not matter as I have tried from elsewhere. I have tried the touch command in the following ways (some will be obviously incorrect but I was desperate)and many more as well as the original format listed.
View 1 Replies View RelatedI've written my script so that it reads in the variables $1 $2 $3 $3....$12I have an input file as follows
word1 1 1 2 3 4 5
word2 1 1 2 3 4 5 6
word3 1 1 2 3 4
[code]...
I am trying to execute executable files in bash without adding ./ I know there must be an alias to add in .bashrc, that must be something like alias PATH=$PATH:. But this seems not to be working.
View 1 Replies View RelatedI've these path:
Code:
xxx/yyy/zzz/0908/aaa/a.txt
xxx/yyy/zzz/0909/aaa/a.txt
xxx/yyy/zzz/0910/aaa/a.txt
fff/ggg/hhh/iii/jjj/0911/aaa/a.txt
fff/ggg/hhh/kkk/0912/aaa/a.txt
and I would like to extract only the number, so that I've get the result
Code:
0908
0909
0910
0911
0911
How can I do it in bash?
We have a custom app that runs on boot on some older hardware running DSL linux, and their startup manager was quite simple. We purchased some newer Asus eeebox's which run xandros and things are quite stable and run nice with 1 exception.The application only runs from the root (/) location. This box auto logs in as 'user' and there is a /home/user/.kde/Autostart folder where you can stick scripts to run at boot. So I have a start.sh script, and with little bash programming tried things such as;
sudo cd /
sudo /startapp.pl
but the errors start spewing with the basic;can't find data/xyz as it's looking in the local.I thought there was a basic cwd (change working directory) but everything I try just forces the run from that location.Any ideas or suggestions are appreciated, but things like can you change the code, etc. can't be done, so it must be a programming thing. The only other thought I had but not sure, can you do a cronjob with @boot or something, that when the box starts, it can run this job as root and fire off?
I am programming in bash and really stuck finding directory names. I have a script to find all the .php files on my / partition which will return the whole path. Is there a way to print directory hierarchy with all those values leaving out the forward slashes.
View 10 Replies View RelatedNow, I have one script called "defcon" defcon gets the current DEFCON level and outputs it using echo.
Code:
#!/bin/bash
DEFCON=`curl -s http://members.tripod.com/~Swat_25/defcon.html | sed -n '/^$/!{s/<[^>]*>//g;p;}' | sed '/^$/d' | grep '[12345]$'`
echo "The current DEFCON level is $DEFCON"
The second script ("tweet") updates my twitter account.
Code:
#!/bin/bash
curl -s -u USER:PASS -d status="$@" http://twitter.com/statuses/update.xml > /dev/null
What I want to do is be able to update my twitter account with the current defcon status (this is really more of a learning thing than something I actually want to be doing). The original script for tweet replaced $@ with $1, but if I use:
tweet `defcon`
it only uses the first word in the string, similarly if I used $2 or $3.So I changed it to $@. The normal function still works, but typing:
tweet `defcon`
updates twitter with nothing.
EDIT I should mention the /dev/null is there to catch the output of curl, otherwise it won't run silently. It still updates twitter normally with the send to /dev/null
i can input chinese in vim ,gvim,gedit ,and also zsh...., but i can't input chinese in bash and sh , i use ibus.
If i login with another account , i can input chinese in bash and sh !
i also diff the locale and env between the two account ,they are nearly the same;
example: when i input chinese ""i type "wq" and space,then bash print :
Display all 4063 possibilities? (y or n)
I'm basically setting up two sshfs mounts and I have it set up so I run one command but type my password twice.Is there an easy to way to input a password using bash and pass that variable to another process asking for a password?
View 5 Replies View RelatedWhen I use the scp command, here is a command prompt "Input password:",Now I want to use a one line command to perform the scp command.I tested the "echo "password" | scp xxx yu@10.xxx.xxx.xxx:/", but failed.
View 2 Replies View RelatedI'm making an bash script.
As input you can input different numbers from 1 to 3.
Depending from the input a text shows up.
As I'm starting to learn bash scripting I'm trying to automatize some tasks I usually perform. I have a notification mail I need to send several times a day. It has this structure:
Quote:
Dear user,
blah blah blah blah
You need to contact the following people:
[code]...
To replace "user", I found this:
Code:
read -p "Please enter username: " username
echo "Dear $username,"
Which probe to be very useful with other simple notifications like this. But I don't know how to manage the email addresses as they are usually more than one and could vary from 1 to 10. They should appear one above the other. I found this: "Here is a little work around. The only thing the user needs to do is hit enter without anything else on a line and it will close out"
Code:
#!/usr/bin/ksh
word=a
until [[ $word = "" ]];do
[code]....
I tried to use it and modify for my needs but I failed, I don't realize yet how can I use it. If possible, I would like to use the until loop like the above example just for learning purposes but any other form will be accepted as well.
having bit of a trouble with path expansion of strings that contain some whitespace and wildcards First my script sources a configuration file that contains array assignments
Code:
...
BACKUP_TARGET_FILES[2]=/boot/config-* # no problems
BACKUP_TARGET_FILES[3]="/root/random dir with space/file*" # this is the problem
...
then later in the script I want to expand BACKUP_TARGET_FILES elements as below
Code:
IFS_DEFAULT="$IFS"
shopt -s nullglob
shopt -s dotglob
IFS=
[code]....
this code seems to work but I'm not quite satisfied with it. I'd like to get rid those IFS changes, but haven't found out a solution as of yet. Problem with default IFS seems to be that with it neither $pattern or "$pattern" work; it either interprets pattern as multiple words (because of spaces) and so expands to wrong paths or it ignores * because it's within quotes.