Programming :: Bash Scripting With "source" Or . (dot) Operator (Cygwin & Ubuntu)?
Jan 22, 2010This one is driving me crazy.
My .bashrc is set as:
if [ -d ~/.bashrc.d ]; then
for file in $(/bin/ls ~/.bashrc.d/); do
[code]....
This one is driving me crazy.
My .bashrc is set as:
if [ -d ~/.bashrc.d ]; then
for file in $(/bin/ls ~/.bashrc.d/); do
[code]....
I have a config file that contains:
my.config:
Code:
Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.
Here is my parse_cmd script:
Code:
I'm having a bit of an issue using overloaded operators in an already overloaded operator. In my following code, I have overloaded the && operator to compare two Course objects. The operator in turn goes to a function which calls other overloaded operators to compare private object variables of that object to compare them.
View 8 Replies View RelatedI have a program that is completed under Linux, it requires library tidy, PCRE and libcurl, which could be found in Cygwin too.
I could compile my linux program through Cygwin and produce an EXE file, however it do require 'cygwin.dll' installed by the users.
I am wondering if I could have someway to produce out a stand-alone EXE file that could run independently from Cygwin ? ( I don't mind to combine that cygwin.dll and the EXE together for a larger EXE file).
I need to find a way to download the attachment from a daily report e-mail to me. The kicker is it will need to be down with a cron tabbed bash script.For example, which linux based CLI client is best suited to be scripted?
View 2 Replies View RelatedI'm trying to put together a script that will quickly run through an archive directory of log files that are named by day of the month 01.gz, 02.gz, 03.gz.... 31.gz. The script uses gunzip -c | grep | wc to count up the total number of hourly occurrences of a filename and outputs the results to stdout.
The only snag I have left is the octal limit when it gets to 08 and 09. I've seen examples using perl and awk, but this script uses a number of nested for loops and if statements that I don't want to have to rewrite in a different syntax. I found that I can use num=10#08 to set that variable to a base 10 instead of a base 8, but then I lose the leading 0 again when it passes the number to the next filename variable.
You are probably using systemd (check it with ps --pid 1) and therefore /etc/init.d isn't considered for autostart. Here can you find some information about systemd and autostart [1]. As far as I know systemd isn't intended to start applications with systemd. I recommend you to use the autostart feature of your window manager or desktop environment or at least the .xinitrc.
[URL] ....
looking to write a dependency map tree that creates a tree structure of object names . This tree will be written to a file and read back to create the tree structure of files . how to write this using bash ?
View 1 Replies View RelatedI have a file called list.txt with on word on each line that changes in length. I'd like to make a menu, each line being its own choice. I pieced together most of it the only thing missing is a failsafe for typing a number out of range
Code:
#!/bin/bash
p=`cat list.txt | awk '{print$1}'`
[code]....
I've been using Ubuntu for about 6 months now, but haven't had a need to start scripting until just recently. I know programming basics, but that's about it.Anyway, I have a program that I would normally run in this manner (note that I didn't create a permanent alias because I've been moving the program around a lot):alias dx='python /path/to/dxProgram.py' dx A_input.dx B_input.dxSo, you see, program dx takes two input files, and 'A' must come before 'B'. I have a folder full of these types of files that I'd like to loop through with this program. They're named as follows:
0_A_input.dx
0_B_input.dx
1_A_input.dx
[code]....
I need to write a bash script that will allow me to manage my "virtual network" (in reality just a bunch of directories and files). I need to obtain something like : I have my own command 'connect'. We can use it in two different modes: user and admin. If I type 'connect adashiu virtual_machine_name, computer will ask about password, if password is correct he will change a prompt to :
adashiu_at_virtual_machine_name >
after that user can start to use commands reserved only for user mode. Analogically with admin mode: prompt 'admin >' and administrator can only use bunch of commands reserved for him. changing prompt and separated commands for user and admin ?
I've got a situation. I'm having GNU bash version 3.00.16(1) on Solaris 10. I need to declare an array say arr1 which will be populated by an output of a command.
declare -a arr1
arr1=( $(/some/command) )
Supposing it will eventually (after executing the command) have element values as -
arr1[0]=1234
arr1[1]=5678
arr1[2]=7890
Now, I need to declare another set of arrays, one for each of the element values above - e.g.
declare -a arr1_1234
declare -a arr1_5678
declare -a arr1_7890
And I also need to populate elements of each of above 3 arrays with output of another command in a loop. So, these arrays will hold values something like -
arr1_1234[0]="abc"
arr1_1234[1]="def"
arr1_1234[2]="ghi"
arr1_5678[0]="jkl"
arr1_5678[1]="mno"
arr1_5678[2]="pqr"
arr1_7890[0]="tuv"
arr1_7890[1]="xyz"
arr1_7890[2]="aab"
I'm able to declare and populate arr1[*]. My question is how do I declare, populate and print the subsequent arrays and their elements?I am feeling rather thick to get this working.
I have wrote a 1 line command that parses a file, locates the IP Address in the file and then trims the output the way I want it, and then sorts numerically and by uniqueness and then >> appends to output.txt
I can get all the IP's into 1 file "output.txt", but what I am really looking for is some type of way to create a text file, for each IP it finds labeled xxx.xxx.xxx.xxx.txt and also put that ip address into that file..
xxx.xxx.xxx.xxx = the ip address it finds
I need to be able to compare a file date with system date and delete files older than 30 days.
the file name is basically
error_log.03222011
of course the extension is the date the file was created.
Oh and before i get hammered I looked everywhere but am unable to make sense of what I found.
pretty simple. how would you background a process from a script and get its process id at the same time?
View 6 Replies View RelatedI am trying to create a custom service to manage a minecraft server what runs in a screen session (this is to allow easy console access as opposed to running it as a nohup background process). I am hitting two main issues with this script so far and wondering if anybody is able to shed some light on it, considering I am far from the greatest BASH scripter on Earth.
The issues are related to start and stop. the first issue with start is there is a command run "screen -dmS minecraft java -Xms1024M -Xmx1024M -jar /minecraft/minecraft.jar nogui" what doesn't appear to work, however when run from console (copy and pasted) this command seems to run perfectly. I am uncertain as to why this is not working within the script. Also if run from a script in /minecraft it also appears to work but in the minecraftd script I have created at /etc/init.d it does not work. I think the issue might be related to the location but am not certain on it, nor how to resolve it.
the second issue with stop is that it works sometimes but at other times it does not, overall it seems to work about 30~50% of the time. When it works it passes a couple of disconnection messages to the screen session and then gives the stop command (the command to gracefully terminate the minecraft server). It seems to work more often when using screen that I attach to the minecraft session while it is running but really not sure if this is an issue with my scripting or an issue with how I am passing things to screen.
The full code in /etc/init.d/minecraftd is below
Code:
#!/bin/bash
## Script Information
## Script Author: Berwick East
[code]....
I was wondering if there is way to hide passwords in bash scripts. For example: I have to write a script to export a full ldap structure, and I'm using the ldapsearch -y passwordfile, where password file is a plain text file that contains the password. Is there a way to hide the password from that file?
I was thinking to remove the r attribute from the file and before the script is lunched to put the attribute back, but is not a good solution, the same with immutable attribute.
At my wit's end I can't find anything that I understand well enough to use. This is for a Unix class, we are working with shell scripting. File1 has 5 in it and File2 has 100 in it.The teacher wants us to read the values then do the math. This is what I have so far:#!/bin/bashvar1='cat File1'var2='cat File2'var3=`echo "scale=4; $var1 / $var2" | bc`echo The final result is: $var3
View 9 Replies View RelatedIs there a way to process individual characters one-by-one from a text file in Bash, or is that hoping for a little too much from this lovable old clunker?
View 13 Replies View RelatedI 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 Relatedi'm in the process of learing C++. currently i'm creating shell scripts to get things done. i'm just curious how, as a programmer using C++ you would get a similar job done.as an example i have a script that takes the contents of files, pipes it to some sed and awk commands, which is piped to create a new file. that file is then imported into a mysql database.if you were going to do this in C++, would you call the sed/awk programs to modify the file, or can it be done within the program itself? i'm probably jumping the gun here because i've just started learing about pointers so this is above my ability
View 12 Replies View Relatedi am using putty to connect to the linux server and i am using nano as my text editor to write a bash script.
this is my script:
echo "Please enter your Username"
read userName
userName= grep $USER /etc/passwd | cut -d: -f5
echo "Welcome " $userName | cat >> output.txt
the problem i have is that when i enter my username, the output (my real name) does not display in the output.txt. instead it displays in putty. so when i run my script in putty it shows the message to enter username and after i enter my username my real name appears below it. i want it to show in the output.txt
in 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'm writing a script to execute bash commands in the PHP CLI. I would like to suppress errors from bash and write my own error message if an error occurs. So far I have this (assuming log.txt doesn't exist!):
Code:
tac log.txt 2>/dev/null
Which works as expected, tac kicks up an error but the error is suppressed, but when I use this:
Code:
tac < log.txt 2>/dev/null
I get:
Code:
bash: log.txt: No such file or directory
The tac error is suppressed but bash still gives me a dirty error.
What options should I use when I'm using the sort command to sort the top 5 CPU processes (ps -eo user,pid,ppid,%cpu,%mem,fname | sort ??? | head -5) showing max to min usage?
View 2 Replies View RelatedI want to edit the environment with a bash script, a part of my script is showed in the post. Its not everything, but the rest is working fine. At the begin of my script I've the follow line Code: #!/bin/bash
set -e First I tried with this solution. Code: sudo chmod 777 /etc
sudo rm /etc/environment
echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ruby/bin"' > */etc/environment
sudo chmod 755 /etc
source /etc/environment Error, source not found
The second solution was this:
Code: sudo chmod 777 /etc
sudo rm /etc/environment
echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ruby/bin"' > */etc/environment
sudo chmod 755 /etc
. /etc/environment
This one didn't give an error, but if I try this:
Code: ruby -v got an error
so the environment didn't worked.
If I use both commands
Code: source /etc/environment
Code: . /etc/environment
In the terminal, without a bash script, it works, so if I do
Code: ruby -v
It works and showed the right version.
I am using "if" to force a word under the condition that the first letter of that word must be a letter of the alphabet, regardless of capitalization, using the " "" != "" " syntax.
Like so:
Code:
if [[ "$interface" != "WHAT DO I PUT HERE?" ]] ; then
echo "Invalid input"
exit 1
fi
Is it possible to pass arguments to a source file in a bash script? For example
#!/bin/sh
#
. /dir1/dir1/funclib -a -b
How would you check for the passed arguments in funclib without getting confused with any arguments passed to the main script?
I have read where C is first converted to Assembly before its final compilation to binary. Is there a way to do this with Bash commands? I would like the understanding that Assembly allows to Bash somehow.
View 14 Replies View Related