Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7176381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:29:43+00:00 2026-05-28T16:29:43+00:00

I’m trying to write a script to login to a Drupal website automagically to

  • 0

I’m trying to write a script to login to a Drupal website automagically to put it into maintenance mode. Here’s what I have so far, and the grep gives me back the line I want.

curl http://www.drupalwebsite.org/?q=user | grep '<input type="hidden" name="form_build_id" id="form-[a-zA-Z0-9]*" value="form-[a-zA-Z0-9]*"  />'

Now I’m kind of a Linux newbie, and I’m using Cygwin with BASH. How would I then pipe the output and use a command to get the value of the id attribute from the output that grep generated? I’ll be using this substring later to do another curl request to actually submit the login.

I was looking at using expr but I don’t really understand how I would tell expr “oh hey this stdin data I want to you manipulate in this way”. It seems like the only way I could do this would be by saving off the grep output in a variable and then feeding the variable to expr.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:29:44+00:00Added an answer on May 28, 2026 at 4:29 pm

    Use sed to trim the results you get from your grep, ie.

    edit : added myID variable, use any name you like.

    myID=$( 
      curl http://www.drupalwebsite.org/?q=user \
      | grep '<input type="hidden" name="form_build_id" id="form-[a-zA-Z0-9]*" value="form-[a-zA-Z0-9]*"  />' \
      | sed 's/^.* id="//;s/" value=.*$//'
    )
    
    
    #use ${myID} later in script
    printf "myID=${myID}\n"
    

    The first part removes the ‘front’ part of the string, everything up to the id=", while the 2nd part removes every " value= .....

    Note that you can chain together multiple sub-replace actions in sed by separating them with the ‘;’.

    edit2
    Also, once you’re using sed, there’s no reason to use grep, try this:

    myID=$( 
      curl http://www.drupalwebsite.org/?q=user \
      | sed -n '\@<input type="hidden" name="form_build_id" id="form-[a-zA-Z0-9]*" value="form-[a-zA-Z0-9]*"  />@{
           s\@^.* id="@@
           s\@" value=.*$@@p
       }'
    )
    

    ( It’s a good habit to get into to removing unnecessary processes. It may not matter in this case, but if you get to where you are writing code that will be executed 1000’s of time in a hour, then having an extra grep when you don’t need it is creating 1000’s of extra processes that don’t need to be created.)

    You may have to escape the ‘< and >’ chars like ‘\< >’ or , worst case ‘[<] [>]’.

    I’m using the ‘@’ as the reg-ex replacement separator now to avoid having to escape any ‘/’ chars in the srch-target string. And I continue using it in the whole example, just to be consistent. For some seds you have tell them that you’re using a non-standard separator, hence the leading \@ at the front of each block of sed code.

    The -n means “don’t default print each line of input”, and because of that, we have to add the ‘p’ at the end, which means print the current buffer.

    Finally, I’m not sure about your regular expression, particularly the -[a-zA-Z0-9]*, this means zero or more of the previous character (or character class in this case). Typically people wanting at least one alpha-numeric, will use -[a-zA-Z0-9][a-zA-Z0-9]*, yes OR [[:alnum:]][[:alnum:]]*, but I don’t know your data well enough to say for sure.

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.