It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Right now I'm stuck with this project in having to pull information from an excel file to create users. The script requires the following.
Create accounts for the employees
Place them into his or her own department group
Set an initial password using his or her employee ID
Send an email containing their new account and password
show progress with dots on the screen
I'm getting close but am getting EOF errors on line 8 and 13 see script here
#!bin/bash
echo $(pwd)/employeesdata.xls
Path=$($pwd)/employeesdata.xls
read Path
if [ -e $Path ];
then
Username= [ grep $(Username) $Path | cut -f1 -d `]'
Password= [ grep $(Password) $Path | cut -f2 -d `]'
useradd -- b $Username
echo $Password | /usr/bin/passwd --stdin $Username
fi
exit
I know it doesn't have the email portion yet.
PS-UserScript: line 8: unexpected EOF while looking for matching `''
PS-UserScript: line 13: syntax error: unexpected end of file
You can use Spreadsheet::ParseExcel for this task:
First make sure cpanm is installed:
$ cpan App::cpanminus
Then install the module:
$ cpanm Spreadsheet::ParseExcel
Once installed, you will be able to use the parsing script that you have copied into your question. That script will fetch each cell one at a time, but you'll still need to do something with those values once read. Depending on how the spreadsheet is setup (if you provide a sample or at least the headers that would be helpful), you would want to gather the info you need as you iterate over the rows, and then perform the desired actions using the data you collected.
Also, I want to point out that the file you parse has to be in the older *.xls format. ParseExcel will not parse *.xlsx files, so first save in the older format using Excel if required.
This simple python script iterate over each cells/rows, that will be a good start I think :
#!/usr/bin/python
from openpyxl import load_workbook
wb = load_workbook(filename = 'file.xlsx', use_iterators = True)
ws = wb.get_sheet_by_name(name = 'Feuil1') # ws is now an IterableWorksheet
for row in ws.iter_rows(): # it brings a new method: iter_rows()
for cell in row:
print cell.internal_value
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a csv file which has two columns: column A for image links and column B for names. First and second columns are comma separated. I need to download all files in column A and assign them names in column B. I have tried the syntax below:
#!/bin/bash
while IFS=',' read -r url filename
do
wget -O $filename $url
done < urls.csv
However, I got these errors:
line 2: $'\r': command not found
line 6: syntax error near unexpected token `done'
line 6: `done < urls.csv'
I am beginner with bash, any help with this?
There are several alternatives, for example using awk, to process a file with field separator characters like a CSV.
However, I will try to KISS this specific case:
Iterate through your CSV file (while)
Get each line fields (IFS is used to set ',' as field separator)
Use them with wget -O option to specify a filename
e.g. something like this:
#!/bin/bash
while IFS=',' read -r url filename
do
wget -O $filename $url
done < yourfile.csv
edit. Just copy pasted your snippet (which lacks proper identation inside the while loop..), and works properly
Perhaps you could share how are you executing that snippet ?
I'm saving it in 'test.sh' and launching it like this, having "urls.csv" file in same folder:
./test.sh
So basically i have this issue with my Easter calculator, its a bash script that i have checked on shellcheck but with little to no luck, this is the code :
#!/shell/bash
read -r -p year
Am19=$((year% 19))
m19=$((19*(Am19)))
Am4=$((year%7))
m4=$((19*(Am4)))
Am2=$((year%4))
m2=$((2*(Am2)))
Av2=$((16+(m19)))
v2=$((Av2%30))
Av1=$((6*(v2)+m4+m2))
v1=$((Av1%7))
p=$((v1+v2))
echo "$p"
Everything appears fine but every time i input a number it always comes out with the result 21
I cant spot any issue, any help would be highly appreciated.
Very interesting issue, especially since shellcheck didn't point out the problem. The problem is in the first line
read -r -p year
Here year is not a variable name but a prompt (a literal string to be printed) given to -p. From help read (shortened version):
read [-r] [-p prompt] [name ...]
If no NAMEs are supplied, the line read is stored in the REPLY variable.
The string entered by the user is stored in the variable REPLY and not in year. The variable year remains unset and will expand to 0 in an arithmetic context like ((…)).
Use read -r -p year year to fix the problem, or even better
read -r -p 'enter a year: ' year
Further improvements
Is #! /shell/bash really correct? I never heard of a system using such a path. I would expect /bin/bash.
You can do assignments inside ((…)), there is no need for a subshell. Write ((a=b+c)) instead of a=$((b+c)).
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Shell script to accept two parameters , i had a script file named createproject.sh
#!/bin/bash
echo "Project Name :$1 "
echo "Group Id : $2 "
mvn archetype:generate -DgroupId=$2 -DartifactId=$1 -DarchetypeArtifactId=maven- archetype-quickstart -DinteractiveMode=false
cd $1
mvn eclipse:eclipse -Dwtpversion=2.0
and i had to execute this by command
sh createproject.sh projectname com.test.app
where projectname and com.test.app are requires project name and package structure but i need to do something like
sh createproject.sh -P projectname and -G com.test.app
so that the user can be informed as -P : Project Name and -G : group Id .Please let me know the changes
Example:
#!/bin/bash
echo "the $1 eats a $2 every time there is a $3"
echo "bye:-)"
source - wikia
Check the Bash's documentation about Positional Parameters...
A positional parameter is a parameter denoted by one or more digits, other than the single digit 0. Positional parameters are assigned from the shell’s arguments when it is invoked, and may be reassigned using the set builtin command. Positional parameter N may be referenced as ${N}, or as $N when N consists of a single digit. Positional parameters may not be assigned to with assignment statements. The set and shift builtins are used to set and unset them (see Shell Builtin Commands). The positional parameters are temporarily replaced when a shell function is executed (see Shell Functions).
When a positional parameter consisting of more than a single digit is expanded, it must be enclosed in braces.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
hi im new to linux and need help with a shell script i am writing to automatically find the ip of ftp servers and copy files to them. this is the code i have but it errors when run
USER=anonymous
PWD=any
PORTCHECK="1"
for IP in 'sqe 6 250';
do
PORTCHECK= nmap -p21 -oG - 192.168.1.$IP | grep '21/open'
if [$PORTCHECK != "1" ]; then
ftp -p -n -i -v 192.168.1.$IP
user $USER $PWD
cd "Mounted Volume"
put foo
put bar
bye
if
CHECKPORT="1"
done
and the error is
./newscrpt: line 19: syntax error near unexpected token `done'
./newscrpt: line 19: `done'
this is being used to copy file to multiple winCE media system after reinstall please help i cant work it out
You meant to say fi instead of if just above CHECKPORT I think.
If you look at the structure of if statements you will notice the that they need a then and fi. See bellow:
if [ conditional expression ]
then
//stuff
fi
Instead of writing for IP in 'sqe 6 250'; (broken code with seq), use :
for IP in {6..250}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I haven't got Linux on my computer at the moment, so I was wondering if someone can test this code I wrote.
It is supposed to rename a file extension when you type something like this, to run it, into the terminal:
chaxxx zzz yyy *.zzz
"chaxxx" being the name of the file.
Here's the code I wrote:
>>deleted<<
Use an online compiler & interpreter for your tests. ideone supports Bash Script too.
EDIT:
It does work. ren.sh is your script name, here you go:
$ ls
asdf.doc ren.sh text.txt
$ ./ren.sh txt doc *.txt
text.txt
text
$ ls
asdf.doc ren.sh text.doc
Have you looked at the rename command? You are pretty much reinventing the wheel here.
From man rename
rename .htm .html *.htm
will fix the extension of your html files.
Edit
If you are going to do it yourself in bash then I would suggest the following code instead. Here are its benefits:
It handles files with spaces in
their names
It checks to see if the file it's about to modify actually
ends in the extension you want to
change before it attempts to mv
it.
It uses native Parameter Expansion syntax rather than call the external binary basename
It checks to see if the # of input parameters is at least 3, otherwise it echos a usage message and exits
It uses a for-loop with indirection rather than calling the test with shift
#!/bin/bash
if (( $# < 3 )); then
echo "Usage: $0 oldExt newExt files"
exit
fi
EXTf=$1
EXTt=$2
for (( i = 3; i <= $#; i++)); do
NAME=${!i}
if [[ "${NAME##*.}" == "$EXTf" ]]; then
mv "$NAME" "${NAME%.*}.$EXTt"
fi
done