bash problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash problem
# 1  
Old 10-23-2010
Hammer & Screwdriver bash problem

hello i am new with linux
hello unix forum.

i have big problem i want to install the samp server for every user folder for ex..
samp for my frined name fred fredsamp
then i want create more samp to my firend lee
i want folder name will be leesamp
i want to know how make the script put the name of the user as folder and make it automaticlay
i mean to this $namefolder(user)
for every install the install will change the name for this code
"echo write user [type username folder name]"
then after this
this the code for copy files cp -r ../files/beckup/sa-mp-steam $user
the orginal place of the samp installer is root/desktop/2/files/beckup/sa-mp-steam
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

A bash problem

Hi, I'm fairly new to unix, and I have the following problem: I know that if I type, "ps -ef | grep process", this will return some information about the process named 'process'. What I need this to do is be piped to an extra search that pick's out process' PID. How do I do this? Thanks in... (5 Replies)
Discussion started by: bogof_tom
5 Replies

2. Shell Programming and Scripting

Problem With Bash Scripting

What's up guys, I am currently trying to figure out the answer to this question and I cannot for the life of me! The question is : "Explain how to do the following in UNIX/Linux shell script. You are not expected to remember the exact command syntax, but explain approximately how you would... (1 Reply)
Discussion started by: malikirl
1 Replies

3. Shell Programming and Scripting

zero padding problem (bash)

Hi there, I need to loop some values, for i in $(seq $first $last) do does something here donefor $first and $last, i need it to be of fixed length 5. so if the input is 1, i need to add zeros in front such that it becomes 00001. It loops till 99999 for example, but the length has to be... (4 Replies)
Discussion started by: jremio
4 Replies

4. Shell Programming and Scripting

Problem with bash if

Hi, i am making a little script that when its invoked with p or f, it will do different things (p will ask the user to input an string and it will count its words , and f will ask the user a directory and will list the number of files in that directory. But if wont get the comparation string... (1 Reply)
Discussion started by: lamachejo
1 Replies

5. Solaris

bash problem?

I am using SunOS 5.9 and have the following outcome when using the sh and bash shells; has anyone else had this: (tests behave differently) bash-2.05$ ksh $ if echo $SHELL; uname -a;; then echo yessssssssssssss; else echo nooooooooooooooo; fi SunOS s036cln001014 5.9 Generic_118558-27 sun4u... (4 Replies)
Discussion started by: Cliffcard
4 Replies

6. Shell Programming and Scripting

bash problem with if

#!/bin/bash # This script takes two arguments: <path> and <dir>. It has to copy in <dir> #+ all regular files in <path> with .c extension containining at least one while #+ instruction and one if instruction. if then for file in $(ls "$1" | grep "\.c$") do if # doesn't... (9 Replies)
Discussion started by: Luke Bonham
9 Replies

7. Shell Programming and Scripting

bash problem

I have a ksh script with the following code and working fine under ksh. IFS=$IFS IFS=: while read a b c do test "$a" = "$oraserver" && { orahome=$b; break; } echo $orahome done < /var/opt/oracle/oratab2 IFS=$_IFS ... (13 Replies)
Discussion started by: talashil
13 Replies

8. Shell Programming and Scripting

problem about '..' in bash

There is an interview question about UNIX bash: Some shells like bash try to make '..' always work propery, namely, from home directory, cd ../$USER will place you in your home directory. Does bash always get this behavior correct? Anyway can provide any example that bash doesnt work well? ... (4 Replies)
Discussion started by: usfish
4 Replies

9. Shell Programming and Scripting

Bash problem

Hello there, I'm a beginner in bash programining and I have a problem with the interpretetion of the code: sed -e "s/\(*\):.*/\1/" in this for loop: for process in $(sed -e "s/\(*\):.*/\1/" /etc/passwd) thx for any help edgehead (3 Replies)
Discussion started by: edgehead
3 Replies

10. Shell Programming and Scripting

Bash while loop problem

Hi, I'm having a problem with the while loop in bash. I try the following script: #!/bin/bash while true do echo "test" done When I try this, it gives me this error: while: Too few arguments. What am I doing wrong? Thanks (5 Replies)
Discussion started by: Kweekwom
5 Replies
Login or Register to Ask a Question
Imager::Cookbook(3pm)					User Contributed Perl Documentation				     Imager::Cookbook(3pm)

NAME
Imager::Cookbook - recipes working with Imager DESCRIPTION
Various simple and not so simple ways to do things with Imager. FILES
This is described in detail in Imager::Files. Reading an image from a file my $image = Imager->new; $image->read(file=>$filename) or die $image->errstr; See Imager::Files. Writing an image to a file $image->write(file=>$filename) or die $image->errstr; Write an animated GIF # build an array of images to use in the gif my @images; # synthesize the images or read them from files, it doesn't matter ... # write the gif Imager->write_multi({ file=>$filename, type=>'gif' }, @images) or die Imager->errstr; See "Writing an animated GIF" in Imager::Files for a more detailed example. Reading multiple images from one file Some formats, like GIF and TIFF support multiple images per file. Use the read_multi() method to read them: my @images = Imager->read_multi(file=>$filename) or die Imager->errstr; Converting from one file format to another This is as simple as reading the original file and writing the new file, for single images: my $image = Imager->new; # Imager auto-detects the input file type $image->read(file => $input_filename) or die $image->errstr; # Imager derives the output file format from the filename $image->write(file => $output_filename) or die $image->errstr; # or you can supply a type parameter: $image->write(file => $output_filename, type => 'gif') or die $image->errstr; The main issue that can occur with this is if the input file has transparency and the output file format doesn't support that. This can be a problem when converting from GIF files to JPEG files for example. By default, if the output format doesn't support transparency, Imager will compose the image onto a black background. You can override that by supplying an "i_background" option to "write()" or "write_multi()": $image->write(file => "foo.jpg", i_background => "#808080") or die $image->errstr; Some formats support multiple files, so if you want to convert from say TIFF to JPEG, you'll need multiple output files: my @images = Imager->read_multi(file => 'input.tif') or die Imager->errstr; my $index = 1; for my $image (@images) { $image->write(file => sprintf('output%02d.jpg', $index++)) or die $image->errstr; } Transparent PNG To save to a transparent PNG (or GIF or TIFF) you need to start with an image with transparency. To make a transparent image, create an image object with 2 or 4 channels: # RGB with alpha channel my $rgba = Imager->new(xsize => $width, ysize => $height, channels => 4); # Gray with alpha channel my $graya = Imager->new(xsize => $width, ysize => $height, channels => 2); By default, the created image will be transparent. Otherwise, if you have an existing image file with transparency, simply read it, and the transparency will be preserved. IMAGE SYNTHESIS
Creating an image To create a simple RGB image, supply the image width and height to the new() method: my $rgb = Imager->new(xsize=>$width, ysize=>$height); If you also want an alpha channel: my $rgb_alpha = Imager->new(xsize=>$width, ysize=>$height, channels=>4); To make a gray-scale image: my $gray = Imager->new(xsize=>$width, ysize=>$height, channels=>1); and a gray-scale image with an alpha channel: my $gray_alpha = Imager->new(xsize=>$width, ysize=>$height, channels=>2); When a new image is created this way all samples are set to zero - black for 1 or 3 channel images, transparent black for 2 or 4 channel images. You can also create paletted images and images with more than 8-bits per channel, see Imager::ImageTypes for more details. Setting the background of a new image To set the background of a new image to a solid color, use the box() method with no limits, and "filled=>1": $image->box(filled=>1, color=>$color); As always, a color can be specified as an Imager::Color object: my $white = Imager::Color->new(255, 255, 255); $image->box(filled=>1, color=>$white); or you supply any single scalar that Imager::Color's new() method accepts as a color description: $image->box(filled=>1, color=>'white'); $image->box(filled=>1, color=>'#FF0000'); $image->box(filled=>1, color=>[ 255, 255, 255 ]); You can also fill the image with a fill object: use Imager::Fill; # create the fill object my $fill = Imager::Fill->new(hatch=>'check1x1') $image->box(fill=>$fill); # let Imager create one automatically $image->box(fill=>{ hatch=>'check1x1' }); See Imager::Fill for information on Imager's fill objects. WORLD WIDE WEB
As with any CGI script it's up to you to validate data and set limits on any parameters supplied to Imager. For example, if you allow the caller to set the size of an output image you should limit the size to prevent the client from specifying an image size that will consume all available memory. This is beside any any other controls you need over access to data. See CGI for a module useful for processing CGI submitted data. Returning an image from a CGI script This is similar to writing to a file, but you also need to supply the information needed by the web browser to identify the file format: my $img = ....; # create the image and generate the contents ++$|; # make sure the content type isn't buffered print "Content-Type: image/png "; binmode STDOUT; $img->write(fd=>fileno(STDOUT), type=>'png') or die $img->errstr; You need to set the Content-Type header depending on the file format you send to the web browser. If you want to supply a content-length header, write the image to a scalar as a buffer: my $img = ....; # create the image and generate the contents my $data; $img->write(type=>'png', data=>$data) or die $img->errstr; print "Content-Type: image/png "; print "Content-Length: ",length($data)," "; binmode STDOUT; print $data; See "samples/samp-scale.cgi" and "samples/samp-image.cgi" for a couple of simple examples of producing an image from CGI. Inserting a CGI image in a page There's occasionally confusion on how to display an image generated by Imager in a page generated by a CGI. Your web browser handles this process as two requests, one for the HTML page, and another for the image itself. Each request needs to perform validation since an attacker can control the values supplied to both requests. How you make the data available to the image generation code depends on your application. See "samples/samp-form.cgi" and "samples/samp-image.cgi" in the Imager distribution for one approach. The POD in "samp-form.cgi" also discusses some of the issues involved. Parsing an image posted via CGI "WARNING": file format attacks have become a common attack vector, make sure you have up to date image file format libraries, otherwise trying to parse uploaded files, whether with Imager or some other tool, may result in a remote attacker being able to run their own code on your system. If your HTML form uses the correct magic, it can upload files to your CGI script, in particular, you need to use " method="post" " and "enctype="multipart/form-data"" in the "form" tag, and use "type="file"" in the "input", for example: <form action="/cgi-bin/yourprogram" method="post" enctype="multipart/form-data"> <input type="file" name="myimage" /> <input type="submit value="Upload Image" /> </form> To process the form: 1. first check that the user supplied a file 2. get the file handle 3. have Imager read the image # returns the client's name for the file, don't open this locally my $cgi = CGI->new; # 1. check the user supplied a file my $filename = $cgi->param('myimage'); if ($filename) { # 2. get the file handle my $fh = $cgi->upload('myimage'); if ($fh) { binmode $fh; # 3. have Imager read the image my $img = Imager->new; if ($img->read(fh=>$fh)) { # we can now process the image } } # else, you probably have an incorrect form or input tag } # else, the user didn't select a file See "samples/samp-scale.cgi" and "samples/samp-tags.cgi" in the Imager distribution for example code. You may also want to set limits on the size of the image read, using Imager's "set_file_limits" method, documented in "set_file_limits()" in Imager::Files. For example: # limit to 10 million bytes of memory usage Imager->set_file_limits(bytes => 10_000_000); # limit to 1024 x 1024 Imager->set_file_limits(width => 1024, height => 1024); DRAWING
Adding a border to an image First make a new image with space for the border: my $border_width = ...; my $border_height = ...; my $out = Imager->new(xsize => $source->getwidth() + 2 * $border_width, ysize => $source->getheight() + 2 * $border_height, bits => $source->bits, channels => $source->getchannels); Then paste the source image into the new image: $out->paste(left => $border_width, top => $border_height, img => $source); Whether you draw the border before or after pasting the original image depends on whether you want the border to overlap the image, for example a semi-transparent border drawn after pasting the source image could overlap the edge without hiding it. If you want a solid border you could just fill the image before pasting the source for simplicity: $out->box(filled=>1, color=>'red'); $out->paste(left => $border_width, top => $border_height, img => $source); TEXT
Drawing text Aligning text Measuring text Word wrapping text Shearing (slanting) or Rotating text This requires that you have Imager installed with FreeType 2.x support installed, and that the font be created using the FreeType 2.x driver, for example: my $font = Imager::Font->new(file=>$fontfile, type=>'ft2'); First you need a transformation matrix, for shearing that could be: my $angle_in_radians = ...; my $tan_angle = sin($angle_rads) / cos($angle_rads); # shear horizontally, supply this as y instead to do it vertically my $matrix = Imager::Matrix2d->shear(x=>$tan_angle); For rotation that would be: my $matrix = Imager::Matrix2d->rotate(radians => $angle_in_radians); or: my $matrix = Imager::Matrix2d->rotate(degrees => $angle_in_degrees); Feed that to the font object: $font->transform(matrix => $matrix); and draw the text as normal: $image->string(string => $text, x => $where_x, y => $where_y, color => $color, font => $font); See samples/slant_text.pl for a comprehensive example, including calculating the transformed bounding box to create an image to fit the transformed text into. IMAGE TRANSFORMATION
Shearing an image Convert to gray-scale To convert an RGB image to a gray-scale image, use the convert method: my $grey = $image->convert(preset => 'gray'); convert() returns a new image. See: "Color transformations" in Imager::Transformations METADATA
Image format When Imager reads a file it does a magic number check to determine the file type, so "foo.png" could actually be a GIF image, and Imager will read it anyway. You can check the actual format of the image by looking at the "i_format" tag. my $format = $image->tags(name=>'i_format'); Image spatial resolution Most image file formats store information about the physical size of the pixels, though in some cases that information isn't useful. Imager stores this information in the tags "i_xres" and "i_yres", and this is always stored in dots per inch. Some formats, including TIFF and JPEG allow you to change the units spatial resolution information is stored in, if you set the tag that changes this the Imager will convert "i_xres" and "i_yres" to those units when it writes the file. For example to set the resolution to 300 dpi: $image->settag(name => 'i_xres', value => 300); $image->settag(name => 'i_yres', value => 300); If you want the file format to store the resolution in some other unit, for example you can write a TIFF file that stores the resolution in pixels per centimeter, you would do: # 150 pixels/cm $image->settag(name => 'i_xres', value => 150 * 2.54); $image->settag(name => 'i_yres', value => 150 * 2.54); $image->settag(name => 'tiff_resolutionunit', value => 3); Keywords: DPI AUTHOR
Tony Cook <tony@develop-help.com> SEE ALSO
Imager, Imager::Files, Imager::Draw. perl v5.14.2 2012-02-22 Imager::Cookbook(3pm)